From 8ac6b7553aff962ed521ca5b58f378744821ae67 Mon Sep 17 00:00:00 2001
From: Oria By default, By default, Alternatively, you could define a new method that uses the more flexible By default, You can also override this feature by setting the cache property globally using This is a shorthand Ajax function, which is equivalent to: This is a shorthand Ajax function, which is equivalent to: The script is executed in the global context, so it can refer to other variables and use jQuery functions. Included scripts can have some impact on the current page. The callback is fired once the script has been loaded but not necessarily executed. Scripts are included and run by referencing the file name: The script is executed in the global context, so it can refer to other variables and use jQuery functions. Included scripts can have some impact on the current page. The callback is fired once the script has been loaded but not necessarily executed. Scripts are included and run by referencing the file name: As of jQuery 1.5, you may use As of jQuery 1.5, you may use Prior to jQuery 1.5, the global By default, You can also override this feature by setting the cache property globally using url. See jQuery.ajax( settings ) for a complete list of all settings.Caching Responses
- $.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() 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.
+ To override this feature you can use the settings object signature as of jQuery 1.12:
+
+
+ You can also override this feature by setting the cache property globally using
+$.getScript({
+ url: "foo.js",
+ cache: true
+});
+ $.ajaxSetup():
-
$.ajaxSetup({
cache: true
});
+$.getScript("foo.js");
$.ajax() method.
-
Caching Responses
$.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.
- To override this feature you can use the settings object signature as of jQuery 1.12:
+ You can override this feature by using a settings object, as of jQuery 1.12:
- You can also override this feature by setting the cache property globally using
$.getScript({
url: "foo.js",
@@ -78,7 +78,7 @@ $.getScript({
});
$.ajaxSetup():
+ $.ajaxSetup():
- You can also use
$.ajaxSetup({
cache: true
@@ -86,37 +86,32 @@ $.ajaxSetup({
$.getScript("foo.js");
$.ajax() directly:
-
-jQuery.ajax({
- url: "foo.js",
- dataType: "script", // this part makes the script run
- cache: true,
-}).done(function( script, textStatus ) {
- console.log( textStatus );
-});
-
url. See jQuery.ajax( settings ) for a complete list of all settings.
+ url. See jQuery.ajax( settings ) for a complete list of all settings.
-
$.ajax({
- url: url,
- dataType: "script",
- success: success
+ url: url,
+ dataType: "script",
+ success: success
});
-
- Success Callback
-
-
+
+ Success Callback
+
-
$.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." );
+ console.log( data ); // Data returned
+ console.log( textStatus ); // Success
+ console.log( jqxhr.status ); // 200
+ console.log( "Load was performed." );
});
- Handling Errors
- .fail() to account for errors:
+
+ Handling Errors
+ .fail() to account for errors:
-
$.getScript( "ajax/test.js" )
- .done(function( script, textStatus ) {
- console.log( textStatus );
- })
- .fail(function( jqxhr, settings, exception ) {
- $( "div.log" ).text( "Triggered ajaxError handler." );
-});
- .ajaxError() callback event had to be used in order to handle $.getScript() errors:
-
-$( "div.log" ).ajaxError(function( e, jqxhr, settings, exception ) {
- if ( settings.dataType == "script" ) {
- $( this ).text( "Triggered ajaxError handler." );
- }
-});
- Caching Responses
- $.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 using a settings object, as of jQuery 1.12:
-
-
-$.getScript({
- url: "foo.js",
- cache: true
-});
- $.ajaxSetup():
-
-
-
-$.ajaxSetup({
- cache: true
-});
-$.getScript("foo.js");
-
-
-