ドキュメント

Ajax/jQuery.get

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Ajax

jQuery.get( url, [data][callback][type] )

Load a remote page using an HTTP GET request.
This is an easy way to send a simple GET request to a server without having to use the more complex $.ajax function. It allows a single callback function to be specified that will be executed when the request is complete (and only if the response has a successful response code). If you need to have both error and success callbacks, you may want to use $.ajax.


$.get() returns the XMLHttpRequest that it creates. In most cases you won't need that object to manipulate directly, but it is available if you need to abort the request manually.
Arguments:


urlString
The URL of the page to load.
data (Optional)Map
Key/value pairs that will be sent to the server.
callback (Optional)Function
A function to be executed whenever the data is loaded successfully.
function (data, textStatus) {
  // data could be xmlDoc, jsonObj, html, text, etc...
  this; // the options for this ajax request
}
type (Optional)String
Type of data to be returned to callback function: "xml", "html", "script", "json", "jsonp", or "text".
Examples:

Request 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" } );

pass arrays of data to the server (while still ignoring the return results).

$.get("test.php", { 'choices[]': ["Jon", "Susan"]} );

Alert out the results from requesting test.php (HTML or XML, depending on what was returned).

$.get("test.php", function(data){
  alert("Data Loaded: " + data);
});

Alert out 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" },
  function(data){
    alert("Data Loaded: " + data);
  });

NameType