mre12345
mre12345

Reputation: 1127

How to get array from ajax call in javascript

My ajax call looks like this:

request = new XMLHttpRequest();
request.open("GET","/showChamps?textInput=" + searchChamp.value,true);
request.send(null);
request.onreadystatechange = function () {
if (request.status == 200 && request.readyState == 4) {
  //how do i get my array
}

}; }

I have sent an array from my node.js server but I don't know how to get that array because request.responseText does not give me back an array. Also it would be appreciated if the answer is in javascript.

Thanks in Advance!

Upvotes: 0

Views: 132

Answers (1)

Travis Clarke
Travis Clarke

Reputation: 6681

var xhr = new XMLHttpRequest();

xhr.onload = function() { 
    if(xhr.status === 200) {
        var responseHTML = xhr.responseText,                 // HTML
            responseXML = xhr.responseXML,                   // XML
            responseObject = JSON.parse(xhr.responseText);   // JSON
    } 
};

Upvotes: 2

Related Questions