My question is sorta linked to this answer.
I've tried to the same thing here below but it still says that its undefined.
function Get(callback) {
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status === 200) {
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.open('GET', 'https://search.mtvnservices.com/typeahead/suggest/?solrformat=true&rows=20&q=alexander+mccormick%20AND%20schoolid_s%3A1262&defType=edismax&qf=teacherfirstname_t%5E2000%20teacherlastname_t%5E2000%20teacherfullname_t%5E2000%20autosuggest&bf=pow(total_number_of_ratings_i%2C2.1)&sort=total_number_of_ratings_i%20desc&siteName=rmp&rows=20&start=0&fl=pk_id%20teacherfirstname_t%20teacherlastname_t%20total_number_of_ratings_i%20averageratingscore_rf%20schoolid_s&fq=', true);
xhr.send();
};
var result;
Get(function (err, result) {
result = result.response.docs.map(doc => doc.averageratingscore_rf);
});
console.log(result);
}
I know for a fact that it does grab what I want cause when I adjust the code to this
Get(function (err, result) {
console.log(result.response.docs.map(doc => doc.averageratingscore_rf));
});
The output is not undefined and it says its 2.3 which is what I want the variable result to be.