jQuery Ajax 请求在没有发送的情况下被取消 [英] jQuery Ajax requests are getting cancelled without being sent

查看:51
本文介绍了jQuery Ajax 请求在没有发送的情况下被取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将脚本连接到 Microsoft 的 World-Wide Telescope 应用程序.后者在端口 5050 上侦听命令.它与浏览器在同一台机器上运行(现在是 Chrome,但据我所知,Firefox 7 和 IE 9 的行为是一样的).

I am trying to hook up a script to Microsoft's World-Wide Telescope app. The latter listens on port 5050 for commands. It is running on the same machine as the browser (Chrome right now, but as far as I can tell the behavior is the same with Firefox 7 and IE 9).

我正在发送带有原始 html 文件的Access-Control-Allow-Origin: *"标头,以尝试消除 XSS 限制作为我的问题.

I am sending a "Access-Control-Allow-Origin: *" header with the original html file to try to eliminate XSS restrictions as my problem.

我访问WWT的代码如下:

My code to access WWT is as follows:

$.ajax({
    type: 'POST',
    url: url,
    data: data,
    crossDomain: true,
    success: success,
    dataType: dataType
});

在这种情况下,url 是http://127.0.0.1:5050/layerApi.aspx?cmd=new&..."(显然...这里是一些附加参数的简写).

url in this case is "http://127.0.0.1:5050/layerApi.aspx?cmd=new&..." (obviously ... is shorthand here for some additional parameters).

查看 Chrome 中的网络诊断,我可以看到:

Looking at the network diagnostics in Chrome, I can see this:

Request URL:http://127.0.0.1:5050/layerApi.aspx?cmd=new&...
Request Headersview source
Accept:application/xml, text/xml, */*; q=0.01
Content-Type:application/x-www-form-urlencoded
Origin:http://gwheeler4
Referer:http://gwheeler4/conceptconnect.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1

请求正在发出 - 我看到 WWT 创建了一个新层.但是,我没有收到回调.如果我添加一个被调用的错误回调,但 jqXHR 对象上的错误属性只是错误"并且状态为 0.如果我在 Chrome 中查看网络请求,我会看到(已取消)"作为状态并且没有响应.

The request is going out - I see WWT make a new layer. However, I don't get a callback. If I add an error callback that gets called, but the error property on the jqXHR object is just "error" and status is 0. If I look at the network request in Chrome I see "(cancelled)" as the status and no response.

如果我使用相同的 URL 并将其粘贴到新的浏览器选项卡中,我可以看到响应是预期的 XML.

If I take that same URL and paste it in a new browser tab, I can see that the response is the expected XML.

当然,这里的区别在于这是一个 GET 而不是 POST,但我已经在我的脚本中尝试过,它没有任何区别.

Of course, a difference here is that this is a GET not a POST, but I've tried that in my script and it makes no difference.

我对此感到非常困惑,如果有任何新想法,我将不胜感激.

I'm pretty stumped by this and would appreciate any fresh ideas.

推荐答案

如果其他人遇到这个问题,我们遇到的问题是我们从链接发出 ajax 请求,而不是阻止链接被跟踪.因此,如果您在 onclick 属性中执行此操作,请确保也return false;.

If anyone else runs into this, the issue we had was that we were making the ajax request from a link, and not preventing the link from being followed. So if you are doing this in an onclick attribute, make sure to return false; as well.

这篇关于jQuery Ajax 请求在没有发送的情况下被取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆