1

I'm very new to coding, I'm hoping someone can help me. I have this little bit of code, I am trying to learn this process:

  1. Call Made to URL via GET request (json)
  2. Parse the response from the GET request
  3. Save the response into a variable that I will use later

Any and all help is appreciated!

const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
const awsURL = 'https://cors.io/?http://status.aws.amazon.com/data.json';

function Get(awsURL){
    var request = new XMLHttpRequest();
    request.open("GET", awsURL, false);
    request.send(null);
    return request.responseText;
}

var AWSJson = JSON.parse(Get(awsURL));
console.log("Archived Outages: "+AWSJson.service_name);
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Patrick Hund Nov 26 '18 at 20:20
  • So what error[s] are you getting with the above code when you run it? – epascarello Nov 26 '18 at 20:44

1 Answers1

1

Return value in given address is not in correct json format. Enter the url in your browser and check the output !

Ramin
  • 134
  • 6