中止previous运行Ajax请求 [英] Abort a previous running Ajax request
本文介绍了中止previous运行Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能中止previously运行Ajax请求?
VAR XHR = $阿贾克斯({
键入:POST,
网址:some.php
数据:名称=约翰和放大器;位置=波士顿,
成功:函数(MSG){
警报(数据保存:+味精);
}
});
解决方案
尝试这样的事情
$(文件)。就绪(函数(){
VAR XHR; //全局对象
功能your_function(){
如果(XHR&安培;&安培;!xhr.readystate = 4){
xhr.abort();
}
XHR = $阿贾克斯({
键入:POST,
网址:some.php
数据:名称=约翰和放大器;位置=波士顿,
成功:函数(MSG){
警报(数据保存:+味精);
}
});
}
});
Is it possible to abort a previously-running Ajax request?
var xhr = $.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
解决方案
try something like this
$(document).ready(function(){
var xhr; // global object
function your_function() {
if(xhr && xhr.readystate != 4){
xhr.abort();
}
xhr = $.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
}
});
这篇关于中止previous运行Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文