diff --git a/entries/jQuery.getScript.xml b/entries/jQuery.getScript.xml index be884042..8a425aa1 100644 --- a/entries/jQuery.getScript.xml +++ b/entries/jQuery.getScript.xml @@ -1,128 +1,136 @@ - jQuery.getScript() - - 1.0 - - A string containing the URL to which the request is sent. - - - - - - A callback function that is executed if the request succeeds. - - - Load a JavaScript file from the server using a GET HTTP request, then execute it. - -

This is a shorthand Ajax function, which is equivalent to:

-

+	jQuery.getScript()
+	
+		1.12
+		
+				A set of key/value pairs that configure the Ajax request. All settings are optional except for url. See jQuery.ajax( settings ) for a complete list of all settings.
+		
+		
+			
+			
+			
+			A callback function that is executed if the request succeeds.
+		
+	
+	
+		1.0
+		
+			A string containing the URL to which the request is sent.
+		
+		
+			
+			
+			
+			A callback function that is executed if the request succeeds.
+		
+	
+	Load a JavaScript file from the server using a GET HTTP request, then execute it.
+	
+		

This is a shorthand Ajax function, which is equivalent to:

+

 $.ajax({
-  url: url,
-  dataType: "script",
-  success: success
+	url: url,
+	dataType: "script",
+	success: success
 });
-    
-

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.

-

- Success Callback -

-

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.

+

Success Callback

+

The callback is fired once the script has been loaded but not necessarily executed.

+

Scripts are included and run by referencing the file name:

+

 $.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

-

As of jQuery 1.5, you may use .fail() to account for errors:

-

+		
+

Handling Errors

+

As of jQuery 1.5, you may use .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." );
-});
-    
-

Prior to jQuery 1.5, the global .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

-

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():

-

-$.ajaxSetup({
-  cache: true
-});
-    
-

Alternatively, you could define a new method that uses the more flexible $.ajax() method.

-
- - Define a $.cachedScript() method that allows fetching a cached script: -
+

Prior to jQuery 1.5, the global .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

+

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 using a settings object, as of jQuery 1.12:

+

+$.getScript( {
+	url: "foo.js",
+	cache: true
+} );
+	
+ +

You can also override this feature by setting the cache property globally using $.ajaxSetup():

+

+$.ajaxSetup( {
+	cache: true
+} );
+$.getScript( "foo.js" );
+	
+ +

+
+ + Load the official jQuery Color Animation plugin dynamically and bind some color animations to occur once the new functionality is loaded. Enable browser caching. + - - - Load the official jQuery Color Animation plugin dynamically and bind some color animations to occur once the new functionality is loaded. - - » Run
]]> - -
- - - + + + +