Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

0

replace this

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

with this

var productid = $('#productid').text()
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda