im trying to understand callbacks and get a result (i grab jsonP data via cross-site). It works but it did not work if i wrap it in function. I think the function returns before the request is ready. But i already stuck in callback function?! It seems i understanding something wrong.
Can you guys help me out please?
In head i got this request function:
function checkThis(){
var s = document.createElement("script"),
callback = "...",
url = "https://...?callback=" + callback;
window[callback] = function (data) {
return data.valid;
};
s.src = url;
document.body.appendChild(s);
}
And it is basically working good.
But when i try to load it in body section with:
alert( checkThis() );
It return undefined, i know cos its not ready?! But how to solve. I try to understand the basics!
Is setInterval() a solution?
Thx guys!