Load a JavaScript file dynamically using jQuery
Demo
jQuery.getScript()Load a JavaScript file from the server using a GET HTTP request, then execute it.
Eg:By default, $.getScript() sets the cache setting to false. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. You can override this feature by setting the cache property globally using $.ajaxSetup():
$.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {
console.log( data ); // Data returned
console.log( textStatus ); // Success
console.log( jqxhr.status ); // 200
console.log( "Load was performed." );
});
$.ajaxSetup({Sample code and demo
cache: true
});
Demo
No comments:
Post a Comment