Skip to content

[Javascript] XMLHttpRequest always returns "undefined" #21525

Answered by ghost
ghost asked this question in General
Discussion options

You must be logged in to vote

Hello, @infinite-dreams .

I couldn’t find the solution to the problem, however, I found a different approach to what I wanted to do.

I decided to throw the whole XMLHttpRequest away and tried using fetch. It worked.

Here is the code solution:

var getJSON = (url, callback) => {
    fetch(url).then(async response => {
        callback(await response.json());
    }).catch(err => {
        throw err;
    });
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants