Skip to content

responseXML not being set? #8

@ghost

Description

Hello,

I am trying to use node-XMLHttpRequest to make AJAX calls from JavaScript code running in node.js. The JavaScript code calls a simple PHP-based server app, which returns some XML (see below). The code works fine when running in a browser, but it does not work properly when runing in node.js using node-XMLHttpRequest. The call to the server completes, but there does not seem to be any data in responseXML. Instead, node.js gives me the error:

        var timeValue = http.responseXML.getElementsByTagName("timenow")[0
                                         ^

TypeError: Object has no method 'getElementsByTagName'

The complete text returned by the server is contained in http.responseText. When/how can that text be parsed into XML so that I can grab the "timenow" field? Looking at the code for node-XMLHttpRequest, it looks like only the responseText variable is filled (on line 212) when a "data" response is received. I see almost no references to the responseXML variable.

Is there some other code required for filling/scanning the responseXML variable, which still has to be implemented in node-XMLHttpRequest? Or am I not calling the function properly to receive data in XML format?

The code is below. Thanks for any tips or pointers.

--IO


CLIENT CODE (JS):

var http = new XMLHttpRequest();

function getServerTime() {
var myurl = 'http://kundry/qrate.php';
myRand = parseInt(Math.random() * 999999999999999);
var modurl = myurl+"?rand="+myRand;
http.open("get", modurl, true);
http.onreadystatechange = useHttpResponse;
http.send(null);
}

function useHttpResponse() {
if (http.readyState == 4) {
if (http.status == 200) {
var timeValue = http.responseXML.getElementsByTagName("timenow")[0];
console.log("timenow="+timeValue.childNodes[0].nodeValue);
}
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions