jQueryAjax在IE9中使用RSS XML返回错误
我有一个生成RSS XML的ASPX页面,如下所示:jQueryAjax在IE9中使用RSS XML返回错误,jquery,xml,ajax,Jquery,Xml,Ajax,我有一个生成RSS XML的ASPX页面,如下所示: <?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> <channel> <title>Title</title> <link>http://www.example.com/news</link> <description>An RSS feed for the
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Title</title>
<link>http://www.example.com/news</link>
<description>An RSS feed for the latest news articles.</description>
<language>en-us</language>
<ttl>60</ttl>
<image />
<lastBuildDate>Thu, 11 Jul 2013 16:44:10 GMT</lastBuildDate>
<item>
<title>The Future of News</title>
<image>/uploadedImages/news/Articles/blog.jpg?n=104</image>
<link>http://localhost/news/Articles/5363/</link>
<pubDate>2029-01-11</pubDate>
<formattedDate>today ago</formattedDate>
<summary>Where will news be in 30 years? Check out what sort of news WE think we'll be making!</summary>
<description />
</item>
...
</channel>
</rss>
$.ajax({
dataType: ($.browser.msie) ? "text" : "xml",
url: newsfeed,
cache: true,
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
success: function (data) {
...
该代码可以在Firefox和Chrome中运行,但在IE9中失败。在IE9中,它触发错误条件并显示两个警报,两个警报都只说“错误”
“newsfeed”变量的值为“”,我已使用警报确认了该值
在其他地方,我看到IE不喜欢“xml”数据类型,因此必须使用“文本”来代替
我正在从localhost运行该网站,因此不应该有任何跨域脚本。此问题的解决方案涉及检测正在使用的web浏览器。如果浏览器是IE,那么我使用IE的XMLHttpRequest而不是jQueryAjax。这是我的密码:
var xhReq = new XMLHttpRequest();
xhReq.open("GET", "/Source/Handlers/Search.ashx?q=" + val + "&d=" + dateObj.getTime(), false);
xhReq.send(null);
AjaxSuccess(xhReq.responseText);
AjaxSuccess方法包含成功执行jQuery AJAX代码时调用的相同javascript
所以我让它工作了,但我真的不知道为什么IE不喜欢jQuery方法。您使用的是什么版本的jQuery?另外,将url替换为
/source/fixed/newsrss.aspx
,如果它确实是同一来源,则不需要它的protocol/domain/port部分。jQuery是1.8.3。我将尝试更改url。我只是像你说的那样尝试使用相对路径,但仍然得到相同的结果。