Wednesday, January 11, 2012

jQuery AJAX resolved fail for XML file in IE

I had a jQuery script that gets dynamically generated XML from server. This code worked fine in Chrome and Firefox, but for some reason AJAX deferred object has been resolved as fail in IE, even though response status code was 200 and I could see XML content in Network tab in IE's Developer tool.

$.ajax({
 url: 'generateXml/',
 dataType: 'xml'
})
.done(function(data) {
 alert("success");
})
.fail(function() {
 alert("fail");
});

When I pointed url to static XML file everything worked fine. Only difference I notice is that content type was somewhat different.

For static file it was application/xml, while my dynamically generated file was of type text/xml.



When I changed my backend code for XML generator to set ContentType as application/xml everything worked fine.

No comments:

Post a Comment