jQuery XHR returning error 0 on select platforms
I'm using the code below which works on some CE platforms but will always fail on others. the message I get back is:
ajaxError: 0 error http://site.com/morepath/?_=1314965250990
So the success callback doesn't happen
It also occurs in the web browser so I hope some one is able to point out the simple error and why it happens on some but not o开发者_运维问答thers. Good example: Errors in IE9 but works in Google Chrome
Data.fetchData = function() {
var i = 0;
Data.items = new Array();
SS.log("Data.fetchData");
$.ajax({
url: Define.feedURL,
dataType: "xml",
success: function(data) {
$("#items").empty();
$(data).find("item").each(function() {
var item = $(this);
Data.items[i] = {
'title' : item.find("title:first").text(),
'image' : item.find("url").text(),
'subtitle' : Utils.stripChars(item.find("subtitle").text()),
'summary' : Utils.stripChars(item.find("summary").text()),
'video' : item.find("enclosure").attr('url'),
'pubDate' : item.find("pubDate").text(),
'duration' : item.find("duration").text()
};
i++;
});
Grid.build();
}
});
};
Since you are expecting an xml
response from the ajax
call you should parse the response using $.parseXML
before using and traversing through it in the success callback. Try this.
success: function(data) {
data = $.parseXML(data);
$("#items").empty();
$(data).find("item").each(function() {
var item = $(this);
Data.items[i] = {
'title' : item.find("title:first").text(),
'image' : item.find("url").text(),
'subtitle' : Utils.stripChars(item.find("subtitle").text()),
'summary' : Utils.stripChars(item.find("summary").text()),
'video' : item.find("enclosure").attr('url'),
'pubDate' : item.find("pubDate").text(),
'duration' : item.find("duration").text()
};
i++;
});
Grid.build();
}
精彩评论