开发者

Form plugin handling non-200/301/302 responses

开发者 https://www.devze.com 2023-01-06 03:13 出处:网络
I\'m working with the jQuery Form Plugin. I have my servers send 200 responses on success, which trips the 开发者_开发技巧success listener perfectly fine. Per the standard, 301 and 302 and transparent

I'm working with the jQuery Form Plugin. I have my servers send 200 responses on success, which trips the 开发者_开发技巧success listener perfectly fine. Per the standard, 301 and 302 and transparently redirected by the browser. However, when the server returns, say a 401, the Form Plugin just silently dies. How can I apply a listener to non-200 responses?


The XHR will have the responseStatus in it - you can use the complete handler instead of 'success' and check that property of the xhr.

$.ajax({ // ...
        complete: function(xhr){
           if( xhr.responseStatus == 401 ) {
               alert( 'awww crap' );
           }
         }
      });
0

精彩评论

暂无评论...
验证码 换一张
取 消