How can I stop Ajax request and then continue, for example if status code response is 403
, stop this request and prompt user if he wants to continue or not.
$.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
use
$.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
});
Answer
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.