[英]how to cancel an ajax request and clear info while it is running?
這是我的代碼片段。 默認情況下,“ ajax_info_box”是隱藏的,通過單擊“按鈕”,“ ajax_info_box”將顯示並發送請求,大概需要5秒鍾的時間。 如何通過單擊“取消”取消和清除請求?任何幫助將不勝感激。
$('.ajax_info_box').hide()
$('.button').click(function() {
$('.ajax_info_box').show()
var xhr = $.ajax({
type: "POST",
url:
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
do something here
});
$('.cancel').click(function () {
suppose to kill the request here
$('.ajax_info_box').hide()
});
});
$('.ajax_info_box').hide()
$('.button').click(function() {
$('.ajax_info_box').show()
var xhr = $.ajax({
type: "POST",
url:
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
do something here
});
$('.cancel').click(function () {
xhr.abort();
$('.ajax_info_box').hide()
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.