$.post catch 405 method not allowed error

  jquery, laravel, php

I’m performing a big import with more than 50 excels and some of the excels contain more than 25k rows. The whole process takes about 10/15 minutes to complete.

Although the import is done with success it always returns in the end the laravel error 405 Method Not Allowed.

I believe this has something to do with the amount of time it takes to import because if I don’t import the biggest excel data, it still takes 7/8 minutes, but no error is thrown. And if I only import the biggest excel data, no error is thrown as well.

ini_set('max_execution_time', 3600);

try 
{
    // Import all the content 
} catch (Exception $e)
{
    // Write any errors to log 
    $log->push($e->getMessage());
}

return response()->json(['log' => $log->output()]);

In the jQuery I call the function this way:

$.post(url, function(response)
{

}).fail(function(response)
{
    // Unable to catch here the error
    console.log(response);
});

But unfortunatelly it seems that the fail function isn’t able to catch the error. If it did, I could handle it and still say "Imported with success".

While I was writing this post I made another import that took 12 minutes and the result is the same:

Status Code: 405 Method Not Allowed
"message": "The GET method is not supported for this route. Supported methods: POST.",

But the import was again done success, every data was written into the DB, plus the error makes no sense since I’m not calling it as GET and yes as POST.

Importing a smaller version of data also works without any problem.

How can I handle the problem and suppress/ignore the error?

Source: Laravel

Leave a Reply