jQuery.get()
The jQuery.get()
method in jQuery is used to load data using a HTTP GET request. This is a shorthand Ajax get function to replace the complex $.ajax.
jQuery.get()
syntaxjQuery.get( url [, data ] [, success ] [, dataType ] ) jQuery.get( [settings] )
Parameter | Type | Description |
---|---|---|
url |
String | request url |
data |
PlainObject,String | The data sent to the server |
success |
Function | callback function that is executed if the request succeeds. |
dataType |
String | xml, json, script, text, html(Default: Intelligent Guess ) |
settings |
PlainObject | A set of key/value pairs that configure the Ajax request. |
jQuery.get()
exampleRequest the test.php page, but ignore the return results.
$.get( "test.php" );
Request the test.php page and send some additional data along (while still ignoring the return results).
$.get( "test.php", { name: "John", time: "2pm" } );
Alert the results from requesting test.php (HTML or XML, depending on what was returned).
$.get( "test.php", function( data ) { alert( "Data Loaded: " + data ); });
Alert the results from requesting test.cgi with an additional payload of data (HTML or XML, depending on what was returned).
$.get( "test.cgi", { name: "John", time: "2pm" } ) .done(function( data ) { alert( "Data Loaded: " + data ); });