In an AJAX call, 302 is not followed

后端 未结 4 2139
孤独总比滥情好
孤独总比滥情好 2020-12-28 15:23

I\'m using jQuery 1.6.2 to make a POST AJAX request to a page on the same domain. That page does a 302 redirect to another page.

Now, on my local machine this work f

4条回答
  •  清酒与你
    2020-12-28 16:01

    function doAjaxCall() {
       $.ajaxSetup({complete: onRequestCompleted});
       $.get(yourUrl,yourData,yourCallback);
    }
    
    function onRequestCompleted(xhr,textStatus) {
       if (xhr.status == 302) {
          location.href = xhr.getResponseHeader("Location");
       }
    }
    

    following questions related to your answer. you can find the answer from below links.

    Catching 302 FOUND in JavaScript

    How to manage a redirect request after a jQuery Ajax call

提交回复
热议问题