jQuery, $.getJson() . , , . , .
:
console.log( "loading first file..." );
$.getJSON( "file1.js", function( json ) {
console.log( "first file loaded!" );
});
console.log( "loading second file..." );
$.getJSON( "file2.js", function( json ) {
console.log( "second file loaded!" );
});
console.log( "loading third file..." );
$.getJSON( "file3.js", function( json ) {
console.log( "third file loaded!" );
});
, , 1/2/3 .
What you could do is that all callbacks perform the same function that will store the count of the number of loaded resources, after all of them have been loaded, you can then call your last callback:
$.getJSON( "file.js", function( json ) {
resource_loaded();
});
var total_resources = 0
var loaded_resources = 0;
function resource_loaded(){
loaded_resources += 1;
if ( loaded_resources === total_resources ){
final_callback();
}
}
source
share