Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
url 404 Not Found ajax javascript laravel

when i click at this button to go to the function addToCart()

<input type="submit" class="btn btn-primary" id="ads value="add to cart">

it returns an error the

Request URL: http://127.0.0.1:8000/cart/data/store/

Request Method: POST

Status Code: 404 Not Found

i dont know why please help

here is my code

my button

<input type="submit" class="btn btn-primary" id="ads" value="add to cart">

and my ajax code

$('body').on('click','#ads',function(){

    var productname = $('pname').text();
    var productid = $('productid').text();
    var color = $('#color option:selected').text();
    var size = $('#size option:selected').text();
    var quantity = $('#qty').val();
    $.ajax({
      url: "cart/data/store/"+productid,
      type: "POST",
      dataType: 'json',
      data:{
        color:color,
        size:size,
        quantity:quantity,
        productname:productname,
      },
    });
  
});

and my route

Route::post('cart/data/store/{id}',[App\Http\Controllers\frontend\CartController::class,'addtocart']);
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Looking at your HTML, you are writing this:

<input type="submit" class="btn btn-primary" id="ads value="add to cart">

You're getting a 404 because there is indeed no route without the ID parameter. You're simply not passing it with the HTML tag you got there. So, fixing the syntax would fix your issue.

It should look like this:

<input type="submit" class="btn btn-primary" id="ads" value="add to cart">
about 4 years ago · Juan Pablo Isaza Report

0

I think your route is incorrect.

Route::post('/cart/data/store/{id}',[App\Http\Controllers\frontend\CartController::class,'addtocart']);

$.ajax call the url given below:

'/cart/data/store/'+productid
about 4 years ago · Juan Pablo Isaza Report

0

replace this

var productid = $('productid').text();

with this

var productid = $('#productid').text()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!