سؤال

On success of ajax request, i load a script using,

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

Is there any way i could check if that particular script is already loaded ?

Thanks.

هل كانت مفيدة؟

المحلول

You need only to implement a success callback function.

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

like:

$.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
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top