本文介绍了为什么这jQuery的Ajax调用失败只在IE9中(即使是在IE8和IE7的正常工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,我作出这样一个Ajax调用:

I have a website where I make an ajax call like this:

            // perform an ajax request to generate a new subscriber account
            jQuery.ajax({
                type: 'POST',
                url: '/index.php?option=com_content&view=article&id=45&tmpl=component',
                data: postVars,
                success: handleResponse,
                error: function(jqXHR, textStatus, errorThrown) {
                    alert ('response: ' + jqXHR.responseText);
                    alert ('code: ' + jqXHR.getResponseHeader('X-Subscriber-Status'));
                }
            });

本页面被请求不做任何事情,只是返回一个数字状态code和它工作正常,除了IE9每一个浏览器。该脚本是在同一个域中的页面它的要求所以不应该有交叉域名脚本的任何问题。

The page being requested doesn't do anything but return a single digit status code and it works fine with every browser except for IE9. The script is hosted on the same domain as the page it's requesting so there shouldn't be any issue with cross domain scripting.

我终于找到了所发生的事情,但我不知道如何解决它。事实证明,Ajax请求,没有任何问题成功完成。我通过使用招看一个网络流量验证了这一点。服务器响应与200 HTTP状态code中的要求和身体不包含任何东西,但一个数字响应code。在这一点上的jQuery执行错误处理程序,而不是成功处理程序将预期(在IE9)。它为什么这样做,我怎么能prevent它?这仅发生在IE9。即使是IE8和IE7的工作只是罚款完全相同的code!正如你所看到的我终于使出检测IE9和使用XmlHtt prequest对象做到这一点(它的工作方式就好了)。

I finally tracked down what's happening but I don't know how to fix it. It turns out that the Ajax request completes successfully with no problems. I verified this by using Fiddler to look a the network traffic. The server responds to the request with an HTTP status code of 200 and the body doesn't contain anything but a single digit response code. At this point jQuery executes the error handler, NOT the success handler as would be expected (in IE9). Why does it do this and how can I prevent it?? This ONLY happens in IE9. Even IE8 and IE7 work just fine with the exact same code! As you can see I finally resorted to detecting IE9 and using an XmlHttpRequest object to do it (which works just fine by the way).

这似乎是一个jQuery的错误给我,但我无法找到我的搜索没有提到这一点。我真的是唯一一个经历这种古怪的行为吗?

This seems like a jQuery bug to me but I can't find any mention of it in my searches. Am I really the only one experiencing this odd behavior?

推荐答案

嗯,我终于找到了问题所在。事实证明,由于某种原因,jQuery的/ IE不正确urlen code双引号。请求的网址是:

Well I finally tracked down the problem. It turns out that for some reason jQuery/IE does not correctly urlencode double quotes. The URL of the request was:

/search.json?callback=jQuery16105234487927080267_1313510362362&q=stocks或股市-blueprint -empireavenue.com -learn和放大器; _ = 1313510362469

/search.json?callback=jQuery16105234487927080267_1313510362362&q=stocks OR "stock market" -blueprint -empireavenue.com -learn&_=1313510362469

在其他浏览器的jQuery执行它看上去像Ajax请求的时间:

In every other browser by the time jQuery performed the ajax request it looked like:

/search.json?callback=jQuery16105234487927080267_1313510362362&q=stocks%20OR%20%22stock%20market%22%20-blueprint%20-empireavenue.com%20-learn&_=1313510362469

/search.json?callback=jQuery16105234487927080267_1313510362362&q=stocks%20OR%20%22stock%20market%22%20-blueprint%20-empireavenue.com%20-learn&_=1313510362469

但不管是什么原因在所有版本的IE它出来是这样的:

but for whatever reason in all versions of IE it came out like this:

/search.json?callback=jQuery16105234487927080267_1313510362362&q=stocks%20OR%20"stock%20market"%20-blueprint%20-empireavenue.com%20-learn&_=1313510362469

/search.json?callback=jQuery16105234487927080267_1313510362362&q=stocks%20OR%20"stock%20market"%20-blueprint%20-empireavenue.com%20-learn&_=1313510362469

这导致服务器返回的数据。

which caused the server to return no data.

这篇关于为什么这jQuery的Ajax调用失败只在IE9中(即使是在IE8和IE7的正常工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 11:47
查看更多