中止jQuery JSONP请求将抛出错误

我正在使用jQuery制作简单的自动提示(autocompleter)插件.不幸的是我必须使用jsonp.没关系,它可以工作,但是当我中止请求时,它会抛出错误.
Uncaught TypeError: Property 'jQuery171036404498340561986_1330693563756' of object [object Window] is not a function

代码

if(xhr) {xhr.abort()};
xhr = $.ajax({
    url: "someurl/getmedata",type: 'get',dataType: 'jsonp',data: {q: "query"},success: function(results) {},error: function() {}
})

使用json,xml或其他请求的经典方式可以正常工作.

安妮的建议?

解决方法

JSONP不使用XMLHTTPRequest,但实际上创建了一个< script>文档中的标记,以便能够进行跨域请求.

您根本无法中止JSONP请求.

它在$.ajax()文档中说明:

Some types of Ajax requests,such as JSONP and cross-domain GET requests,do not use XHR; in those cases the XMLHttpRequest and textStatus parameters passed to the callback are undefined.

至于jQuery 1.5,以前是从$.ajax()返回XHR对象,现在它返回一个超集jqXHR对象,它封装了XHR对象.

When the transport mechanism is something other than XMLHttpRequest (for example,a script tag for a JSONP request) the jqXHR object simulates native XHR functionality where possible.

所以它返回一个对象但实际上没有一些功能,比如.abort().

插件jQuery-JSONP似乎提供了手动中止JSONP请求的可能性.我自己没有用过,但值得一试.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...