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

245
Views
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 answers
Answer question

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