I've got this code:
function fetchSocialCount(type,fileSrc,callback){
var req = new XMLHttpRequest();
req.onload = function(){
if(req.status === 200 && req.readyState === 4){
var countResponse = JSON.parse(req.responseText);
callback(countResponse);
}
}
req.open("GET","../scripts/php/returnSocialCount.php",false);
req.send();
}
var test = fetchSocialCount("img","ez.png",function(count){
return count;
});
console.log(test);
But for some reason, test
is undefined. My AJAX does work, and it returns an object. What's the problem?