Monday, 22 May 2017

node js API call JSON response from within app.js

I am using an api that returns a JSON object. I want to be able to call that that API, and console.log the JSON it returns

    var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
    var xhr = new XMLHttpRequest();
    xhr.open("GET", "http://{WEBSITE}/api/allinfo?name=Roger&Age=30", false);

    xhr.setRequestHeader('Content-Type', 'text/xml');
    xhr.send();

   xmlDocument = xhr.responseXML;
   console.log(xmlDocument);

How can I do this, currently console is logging undefined?



via user7983422

No comments:

Post a Comment