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

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

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 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