0

在ajax请求成功时,我使用加载脚本,

$.getScript(base_url + 'js/js_to_be_loaded.js');

有什么方法可以检查该特定脚本是否已加载?

谢谢。

4

1 回答 1

2

您只需要实现一个success回调函数。

jQuery.getScript( url [, success(script, textStatus, jqXHR)] )

像:

$.getScript(base_url + 'js/js_to_be_loaded.js', onSuccess);

function onSuccess(...)
{
    // in this function you are guaranteed that it is loaded
    // so you can execute code based on the loaded js file or
    // set flags to let your code "know" that it is loaded
}
于 2012-08-21T10:05:48.357 回答