jQuery: If API Load success, do function
Im working with a search flight API and I would like to set few settings when the API is loaded.
Here is how the API is loaded:
skyscanner.load('snippets', '1');
function main(){
var snippet=new skyscanner.snippets.SearchPanelControl();
snippet.setCurrency('GBP');
snippet.setDeparture('uk');
snippet.draw(document.getElementById('snippet_searchpanel'));
}
skyscanner.setOnLoadCallback(main);
This is what I tried but doesn't seem to work:
开发者_Python百科skyscanner.load('snippets', '1', function (responseText, textStatus, XMLHttpRequest) {
if (textStatus == "success") {
alert(test);
}
});
It looks like SkyScanner already has an onload callback, and you've set it to "main()", wouldn't you just put your code where it needs to be (perhaps at the end) of that function?
I don't know the sky scanner api, so I don't know if their "load()" function takes a third parameter. It looks as if it might not, since they apparently provide the separate function setOnLoadCallback().
alert(test);
Where is test
? maybe it should be alert("test")
UPDATE:
OK, I've just looked at skyscanner's API:http://api.skyscanner.net/api/ajax/documentation.html
here is the load function:
skyscanner.load(<i>moduleName, moduleVersion, optionalSettings</i>)
it seems that the 3rd parameter is not for onload event.
You could just test:
skyscanner.setOnLoadCallback(function(){
alert("test");
});
skyscanner.load('snippets', '1');
精彩评论