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

246
Visualizações
why 404 and 405 shows on my live laravel project when I use ajax post request

I have developed simple cart system in laravel for my local client, it has no any issue on my local server but when I publish it on my live server which is infinity free hosting it has multiple issues. When I try to add to cart the product on home page it is showing 404 error, I am using ajax request.

JS CODE:

      jQuery.ajax({
      url: "/add_to_cart",
      method: "post",
      data: jQuery('#formAddToCart').serialize(),
      success: function(result){}

my home page url is "new_shop/" and when I remove the "/" from my js code url it is working perfectly but then it shows error on my product detail page where I am using same function and the url of product detail page is "product-name" like this without "/"; product detail page add to cart is also not working with "url: "/add_to_cart"," this url. I don't know what the confusion is as it is working perfectly on my local server. I think it may be issue of free hosting. Any assistance will be appreciated.

ROUTE WEB.PHP CODE:

            Route::post('add_to_cart',[FrontController::class,'add_to_cart']);  
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are doing it in a wrong way from js code.

You should use name for your routes like this

Route::post('/add_to_cart',[FrontController::class,'add_to_cart'])->name('cart.add');

Now call it from the js code like this

jQuery.ajax({
    url: "{{route('cart.add')}}",
    method: "post",
    data: jQuery('#formAddToCart').serialize(),
    success: function(result){}
})

As I am not sure you have group for your route or not You can try this also

jQuery.ajax({
    url: "{{URL::to('/add_to_cart')}}",
    method: "post",
    data: jQuery('#formAddToCart').serialize(),
    success: function(result){}
})

And make sure that you are passing csrf token in your form data.

This way you don't need to worry about your methodName as well as your url. You just need to provide a name to your routes

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