0

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.

Priyank Kapasi
  • 1,773
  • 2
  • 18
  • 27
  • 1
    Read the [documentation](http://api.jquery.com/jquery.getscript/) ;) – Andreas Aug 21 '12 at 09:59
  • I know neither javascript, nor jquery so good to say if it has built-in method to check one. You can have variable `var x = 0;` increment one when you load your `js` and before loading script, check if `x==0` – Leri Aug 21 '12 at 09:59

1 Answers1

2

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
}
Cranio
  • 9,647
  • 4
  • 35
  • 55