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);
}
dataTypeproperty of the options object you pass to$.ajax. Or you can even use DOMParser to parse xmlparser = new DOMParser; xml = parser.parseFromString(data,'application/xml')wheredatais the argument from your callback