Thursday, 25 February 2010

How to set up your IIS xml Mime type to support jquery Ajax method

How to set up your IIS xml Mime type to support jquery Ajax method:

(1) Inside IIS open out the navigation tree and click properties on the relevant web site.

(2) In the properties box pick the tab and click the mime type button.



Related links:

jQuery.ajax gives "TypeError: Cannot read property ‘documentElement’ of null" on server but not local.

jQuery XML and MIME types


Try running the following jquery javascript:

type: "GET",
datatype: "xml",
url: "Test.xml",
success: parseXml,
error:function(xhr, status, errorThrown) {

It works fine in Firefox.
When run locally it also works fine in Chrome.
But not in IE.

Now put it up on an IIS server.
It still works fine in Firefox.
But IE gives the cryptic: Undefined parsererror
and Chrome gives the only slightly more helpful: "TypeError: Cannot read property ‘documentElement’ of null"

You try changing all the options of the .ajax function you can find and none of them make any difference (such as you might find here: jquery api reference: Ajax method )

You think it might be something to do with the MIME type but you've had a look on IIS and checked the MIME type for xml IS set up - so by now you've spent an hour or so scratching around, and nothing made any difference and you're feeling very frustrated.

Well the answer is as I've indicated above.
It turns out that for the benefit of Chrome and IE, the "type" setting of the ".xml" extension mime-type is absolutely critical for this to parse correctly. Previously mine just said "xml" which was not enough... when I changed it to "text/xml" everything now good.

No comments: