I have a javascript that does this (http is your XMLHttpRequest object)
var r = http.responseXML.getElementsByTagName('item');
The issue is variable r is always an empty list if the response contains non-English character (r.length is 0).
The response header is correctly set
Content-Type: text/xml;charset=ISO-8859-1
This is what the response from the webserver looks like
<?xml version='1.0' encoding='UTF-8'?>
<d>
<r>
<item value="jmob" label="John Möb"/>
</r>
</d>
It happens only in IE (both IE6 and IE8), works in Firefox and Chrome.
If items contain only English characters, it works fine.
Is there a workaround for this ?
You said the response header was correctly set, but it’s not. You’re serving a UTF-8 document, so it should be:
There could be an issue with IE taking the content-type header literally. I can’t say I’ve ever run into this problem, but I don’t use
getElementsByTagNamebecause it doesn’t work with namespaces. You could useselectSingleNode()orselectNodes()instead:XPath gives you much more power than
getElementsByTagName. You might even find that, using the right path, you can ditch one or two of yourifstatements. For full XPath syntax, see http://msdn.microsoft.com/en-us/library/ms256471(VS.85).aspx.