使用jQuery我不能停止Ajax请求并中止()函数 [英] I cannot stop an ajax request using jQuery and abort() function
问题描述
我jQuery是如下:
My jQuery is below:
var x = $.ajax({
dataType: "jsonp",
url: "https://ajax.googleapis.com/ajax/services/search/images?q=google&v=1.0",
success: function(msg){
alert( "Jsonp data: " + msg );
}
});
alert(x); // x is undefined
// x.abort()
您可以试试这个code在这里: http://jsbin.com/iyile3/2/编辑
You can try this code here: http://jsbin.com/iyile3/2/edit
我想停止这种Ajax请求,并停止该Ajax请求的成功的功能。
I want stop this ajax request and stop this ajax request's success function.
但我得到的是,X是不确定的,我想我不会停止这种Ajax请求其成功的功能。
But what I get is that "x" is undefined , I think I doesn't stop this ajax request and its success function.
因此,谁能帮助我?
So can anyone help me?
非常感谢你!
推荐答案
嗯,这是有道理的。
A JSONP
呼叫不是一个普通的 XMLHtt prequest
(其中阿贾克斯()正常返回) 。它不会按照这种方式,因为你不能跳出同源策略
。
A jsonp
call is not an ordinary XMLHttpRequest
(which .ajax() normally returns). It would not work that way since you cannot break out the same origin policy
.
JSON-填充适用于动态脚本标记插入。所以基本上,jQuery的只是创建一个<脚本>在您的网站
标签,并在加载数据。否 XHR
对象都没有。
JSON-Padding works with dynamic script tag insertion. So basically, jQuery just creates a <script>
tag on your site and loads the data over that. No XHR
object at all.
我不认为有一种方法可以及早终止那样的要求,但我希望有人会纠正我在这里,如果我错了。
I don't think there is a way to early abort that kind of request, but I hope someone will correct me here if I'm wrong.
这篇关于使用jQuery我不能停止Ajax请求并中止()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!