jQuery:如果 API 加载成功,则执行函数
我正在使用搜索航班 API,我想在加载 API 时设置一些设置。
以下是 API 的加载方式:
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);
这是我尝试过的方法,但似乎不起作用:
skyscanner.load('snippets', '1', function (responseText, textStatus, XMLHttpRequest) {
if (textStatus == "success") {
alert(test);
}
});
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:
skyscanner.load('snippets', '1', function (responseText, textStatus, XMLHttpRequest) {
if (textStatus == "success") {
alert(test);
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来 SkyScanner 已经有一个 onload 回调,并且您已将其设置为“main()”,您是否只需将代码放在该函数需要的位置(可能在末尾)?
我不知道天空扫描仪 api,所以我不知道他们的“load()”函数是否需要第三个参数。看起来可能不会,因为它们显然提供了单独的函数 setOnLoadCallback()。
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")
更新:
好的,我刚刚查看了 skyscanner 的 API:http://api.skyscanner.net/ api/ajax/documentation.html
这是加载函数:
似乎第三个参数不是用于 onload 事件的。
你可以测试一下:
Where is
test
? maybe it should bealert("test")
UPDATE:
OK, I've just looked at skyscanner's API:http://api.skyscanner.net/api/ajax/documentation.html
here is the load function:
it seems that the 3rd parameter is not for onload event.
You could just test: