0

I have recently learned to use APIS in code, but for my javascript version I've had to learn different ways of doing it, when using what should be the simplest method nothing gets outputted to my chrome console.

const request = new XMLHttpRequest();

request.open('GET','apistuff, true);

request.onload = function() {

let data = JSON.parse(this.response);


console.log(data);
};

HTML file is just empty and calls the javascript file

1 Answer 1

1

Just replace current code with below code and let me know the status

    const request = new XMLHttpRequest();

    request.open('GET', apistuff, true);
    request.send(); 
    // we need to call this send method to open breach between server and client
    request.onload = function() {
       let data = JSON.parse(request.response);
       // if response is in text simply use **request.responseText**


    console.log(data);
    };
Sign up to request clarification or add additional context in comments.

2 Comments

Console still outputs nothing, do I need to call the function to run to output it or look in a different place than chrome console?
Please check recent changes I have insert send method which call the api and onload method will wait for the response. You dont't need to change anything just write send method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.