weixin_33670713 2018-05-03 11:11 采纳率: 0%
浏览 120

处理Ajax自动重定向

I am struggling from 2 days to solve the issue with my Laravel app which I have uploaded on Heroku server. This application is uploading a file through ajax request showing upload progress also on the page and it returns json response.

I have set the Content-Type: application/json and X-CSRF-TOKEN is also valid in the header but still after completing the upload instead of returning valid json response, it setting status to 301 and 302 and move to home page.

I have tested this Laravel app on my local server and its very stable there. I am thinking if there is any way to pause chrome before loading the redirection page by hitting a breakpoint, so I could know whats happening before the redirection. I have already tried this in console:

window.addEventListener("beforeunload", function() { debugger; }, false) but it never trigger a breakpoint. Any help will be appreciated.

  • 写回答

1条回答 默认 最新

  • weixin_33671935 2018-05-03 16:46
    关注

    Finally after 2 hectic days in scrubbing my head with Heroku server, I figured out that Heroku Apache server requires that Laravel route should be set to handle both POST and GET method. In my case I have to use this:

    Route::match(['get', 'post'], '/xls2db', 'HomeController@xls2db')->name('xls2db');

    This does makes sense because after Ajax POST method it returns json response which will only be handled if the route accepts GET method also.

    On my local server I was testing my app with php artisan serve which can GET json response with only POST route.

    评论

报告相同问题?