Catching 302 FOUND in JavaScript

后端 未结 5 2106
予麋鹿
予麋鹿 2020-11-27 03:32

I use jQuery to make an AJAX POST request to my server, which can return HTTP response with status 302. Then JavaScript just sends GET request to this URL, while I\'d like t

5条回答
  •  难免孤独
    2020-11-27 04:27

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

提交回复
热议问题