How to get jQuery.ajax response status?

丶灬走出姿态 提交于 2019-12-05 02:10:50
DRaehal

The issue is that a 301 or 302 is handled directly by the browser due to standards compliance. This status code is not passed on to your ajax call. The only way that you know that the call has completed is in the complete handler, and furthermore there is no useful status given in the jqxhr object passed to complete. The Success and Error handlers will never get called.

We had some legacy ruby camping code that used a redirect to the get() method when a post() method was called so that we could display an updated view via ruby of the resource. When we switched to JavaScript views from camping views, the 301/302 was not passed to the jqxhr object. We had to rewrite the post methods to return 200 to fix the issue.

Here are some stackoverflow posts on the subject.

How to manage a redirect request after a jQuery Ajax call

Catching 302 FOUND in JavaScript

HTTP redirect: 301 (permanent) vs. 302 (temporary)

A tool i found that might possibly be able to help is wireshark. It's free and may be able to find out what is happening with the jqXHR object. It's fairly easy to use but follow these instructions:

http://www.wireshark.org/ Wireshark is a network protocol analyzer for Unix and Windows. I have only brushed the surface with this tool so far but it comes in handy when performing analysis on requests between your machine and others on the network.

Before you start - Wireshark captures every request so only click start when you are ready to capture and click stop when your finished. - You'll need your IP address

Read more about analysing HTTP requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!