Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

185
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

0

replace this

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

with this

var productid = $('#productid').text()
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda