function checkDatabase(){
var query = document.getElementById("input").value;
var modQuery = query.split("@")[1];
var url = "http://www.somesite.com/index.html/?id="+modQuery;
$.getJSON(url, function(data) {
$.each(data, function(i, item) {
console.log(item);
if(item.length < 1){
return false;
} else {
searchResult = {
'name':item[0].screen_name,
'loc':item[0].location,
'tweet':item[0].tweets[0].tweet_text
};
return true;
}
});
});
}
function searchForUser(){
var result = checkDatabase();
console.log(result);
if(result){
console.log(searchResult);
} else {
input.setCustomValidity("Sorry it seems you haven't tweeted about every1speaks yet!");
}
}
I can’t understand what it going wrong here, I’ve seen suggestions at AJAX calls are async (does that mean that they happen when the page is loading?) how can i tweak this to work?
Because you
You will need to put the logic in the
callbackmethod of thegetJSONcall.