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.

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改