rf_wilson rf_wilson - 3 years ago 226
jQuery Question

jQuery Ajax returns error in IE9 with RSS XML

I have an ASPX page that generates RSS XML like this:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<description>An RSS feed for the latest news articles.</description>
<image />
<lastBuildDate>Thu, 11 Jul 2013 16:44:10 GMT</lastBuildDate>
<title>The Future of News</title>
<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 />

I need to call this feed from a jQuery file like this:

dataType: ($.browser.msie) ? "text" : "xml",
url: newsfeed,
cache: true,
error: function (xhr, ajaxOptions, thrownError) {
success: function (data) {

The code works in Firefox and Chrome but fails in IE9. In IE9 it triggers the error condition and displays two alerts that both just say "error".

The "newsfeed" variable has the value of "http://localhost/source/fixed/newsrss.aspx" which I have confirmed by using an alert.

Elsewhere I saw that IE doesn't like the "xml" datatype so has to use "text" instead.

I am running the site from localhost so I there should not be any cross domain scripts.

Answer Source

The solution to this problem involved detecting the web browser that was being used. If the browser is IE then instead of using jQuery AJAX I used IE's XMLHttpRequest. Here is my code:

var xhReq = new XMLHttpRequest();
xhReq.open("GET", "/Source/Handlers/Search.ashx?q=" + val + "&d=" + dateObj.getTime(), false);

The AjaxSuccess method contains the same javascript that is called upon successful execution of the jQuery AJAX code.

So I got it working but I don't really know why IE didn't like the jQuery approach.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download