Как я могу остановить запрос ajax и продолжить? - PullRequest
1 голос
/ 22 февраля 2020

Как я могу остановить запрос 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 голосов
/ 22 февраля 2020

использовать

$.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
           });

Ответ

function requestT(t){


$.ajax({
        url:t,    
        method:"GET",
        async: true,
        xhrFields: {
       withCredentials: true
         }
     }).then(function(data,textstatus,xhr) {

           //your code....
  },

            function(xhr,text,error){


                   var x = prompt("do you want to continue if YES enter 1?");
                   if(x == 1){
                       console.log("reload Request...");
                        requestT(t);
                   }

               }

            );//ajax

        }//func request
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...