如何停止Ajax请求然后继续?

时间:2020-02-22 09:39:46

标签: javascript jquery

如何停止Ajax请求,然后继续执行(例如,如果状态码响应为403),请停止该请求并提示用户是否要继续。

$.ajax({
  url: t,
  method: "GET",
  async: true,
  xhrFields: {
    withCredentials: true
  },
  success: function(data, textStatus, xhr) {
 if (xhr.status == 403) {
      //how can i stop this request call prompt if click ok then
      var check = prompt("Do you want this request?");

      if (check) {
        //success code
      }
    }

  }
}); //ajax

1 个答案:

答案 0 :(得分:0)

使用

h4

答案

$.ajax( ...params... )
     .then(
           function(data, textStatus, jqXHR) { 
                 alert("Success: " +  data);
                 // initiate next sequential operation
           },
           function(jqXHR, textStatus, errorThrown) {
                 alert("Error: " + errorThrown);
                 // initiate next sequential operation
           });