responseXML is returning null

Admin Pro
Tera Contributor

I have a public page which makes a ajax call to service-now to obtain some information and return the result back to the public page. I have the below client script which works fine when using "responseText" to receive the server call, but always returns null if "responseXML" is used. I have tried several different method, but regardless I get nothing but null. Unfortunately, the responseText is the full HTML response which make it quite difficult to get the value you are looking for. My goal is to get this in an XML format where I can use xPath to parse out my exact value. Here is the code:


function onChange(control, oldValue, newValue, isLoading) {
if(newValue == oldValue){
return;
}


var xmlhttp = null;
var list = "";
//code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest();
//code for IE6, IE5
else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var list = xmlhttp.responseText; // this method returns the entire html response
jslog("List 0 " + xmlhttp.responseText);
//Here I tried to convert the string to DOM, so I can parse this in XML, but it doesn't work
var parser=new DOMParser();
var xmlDoc = parser.parseFromString(xmlhttp.responseText, "text/xml");
jslog("New xml Doc is: " + xmlDoc);
var tds = xmlDoc.getElementsByName("body")[0];
jslog("TDS point is: "+ tds);
//...some more code....


}
};

xmlhttp.open("GET","url" + true);
//xmlhhtp.overrideMimeType('text/xml');
xmlhttp.send(null);
//xmlhttp.setRequestHeader("Content-Type", "text/xml");

}

P.S. since my client script is on a public page, I can't use glideAjax call as they are restricted for the public calls.

2 REPLIES 2

JoeLighthall
Giga Contributor

I am having this same issue.   I have found with some users responseXML is not null and with others it is.   I've made a ticket with ServiceNow so hopefully this is resolved for me soon.   I'm guessing this could be a user preference but do not yet know.   I'll post to this if I find a solution.


Callum Ridley1
Tera Guru

I know this is really quite old now, but just in case anyone ends up here wondering how to call GlideAjax from public pages. the answer is actually very simple!



Add the following lines to your Client Callable Script Include:



isPublic: function() {


  return true;


  },



Job done



Callum