Reputation: 4709
I have this code that loads an xml file using javascript:
function getXmlDocument(sFile) {
var xmlHttp, oXML;
// try to use the native XML parser
try {
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", sFile, false); // Use syncronous communication
xmlHttp.send(null);
oXML = xmlHttp.responseXML;
} catch (e) {
// can't use the native parser, use the ActiveX instead
xmlHttp = getXMLObject();
xmlHttp.async = false; // Use syncronous communication
xmlHttp.resolveExternals = false;
xmlHttp.load(sFile);
oXML = xmlHttp;
}
// return the XML document object
return oXML;
}
If the extension of the 'sFile' is not .xml the function returns "" always. What should I do to fix this?
Upvotes: 1
Views: 487
Reputation: 21763
I think it's a problem on the server side: files with another extension than .xml
don't get the MIME type of text/xml
or something alike and the browser('s XML parser) doesn't recognize it as XML.
Be sure that your content is served with the correct MIME type by your server software. With Apache, you can change this in the .htaccess
file. Dynamically generated XML should be sent with an appropriate Content-Type:
header. In PHP, you can do this with the header
function.
Upvotes: 2