jQuery get()メソッド
例
HTTP GETリクエストをページに送信し、結果を返します。
$("button").click(function(){
$.get("demo_test.asp", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
定義と使用法
$ .get()メソッドは、HTTPGETリクエストを使用してサーバーからデータをロードします。
例
「test.php」をリクエストしますが、返される結果は無視します。
$.get("test.php");
「test.php」をリクエストし、リクエストと一緒にいくつかの追加データを送信します(戻り結果は無視します)。
$.get("test.php", { name:"Donald", town:"Ducktown" });
「test.php」をリクエストし、データの配列をサーバーに渡します(戻り結果を無視します)。
$.get("test.php", { 'colors[]' : ["Red","Green","Blue"] });
「test.php」をリクエストし、リクエストの結果を警告します。
$.get("test.php", function(data){
alert("Data: " + data);
});
構文
$.get(URL,data,function(data,status,xhr),dataType)
Parameter | Description |
---|---|
URL | Required. Specifies the URL you wish to request |
data | Optional. Specifies data to send to the server along with the request |
function(data,status,xhr) | Optional. Specifies a function to run if the request succeeds Additional parameters:
|
dataType | Optional. Specifies the data type expected of the server response. By default jQuery performs an automatic guess. Possible types:
|