Question

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.

Was it helpful?

Solution

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top