Reputation: 9634
I'm facing issue in loading the XML data in Javascript. However if i load the same XML in classic ASP it is working, but if i load the same in Javascript its failing.
Here is the code snippet to load XML in classic ASP & it works fine.
set ObjXMLDom = nothing
set ObjXMLDom = server.CreateObject("Microsoft.XMLDOM")
ObjXMLDom.async = False
set objSvr = Server.CreateObject("myComMethod.MyComMethod.1")
ObjXMLDom.loadXML(objSvr.GetHierarchyXML()) 'XML loads perfectly fine from server. even if the special character is Dash –
Response.Write(ObjXMLDom.xml)
code in Javascript to load the XML but it fails for some special characters.
$.ajax("get_xml_from_server.asp", {
type: 'GET',
data: { name: groupID, session: sesionID, Employee: empID },
beforeSend: function () {
},
success: function (data, status, jqXhr) {
//Data has got the XML string, we can see it by putting alert
alert(data);
var myXML = new ActiveXObject("Microsoft.XMLDOM");
myXML.async = false;
myXML.loadXML(data); //Here it fails for some special characters like Dash –
if (myXML.parseError.errorCode != 0)
{
var myErr = myXML.parseError;
alert("You have error " + myErr.reason + myErr.line + myErr.srcText);
}
else {
alert(myXML.xml);
}
Upvotes: 0
Views: 647
Reputation: 163312
I suspect that there is an encoding problem: the XML file is in one encoding, and the parser is trying to decode it assuming a different encoding, and this results in a failure to decode the non-ASCII characters. You have given us no information about encodings, so this is entirely conjectural. Try to establish
(a) what is the actual encoding of the XML "on disk" on the server
(b) what does the XML declaration at the start of the file (if any) say that the encoding is?
(c) what is the media type and encoding of the HTTP response that delivers the XML payload to the browser?
Chances are, I would guess, that there's something you need to change in your web server / HTTP configuration to ensure that XML files are properly delivered.
Upvotes: 1