Phương thức jQuery get ()
Thí dụ
Gửi yêu cầu HTTP GET đến một trang và nhận lại kết quả:
$("button").click(function(){
$.get("demo_test.asp", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
Định nghĩa và Cách sử dụng
Phương thức $ .get () tải dữ liệu từ máy chủ bằng yêu cầu HTTP GET.
Các ví dụ
Yêu cầu "test.php", nhưng bỏ qua kết quả trả về:
$.get("test.php");
Yêu cầu "test.php" và gửi một số dữ liệu bổ sung cùng với yêu cầu (bỏ qua kết quả trả về):
$.get("test.php", { name:"Donald", town:"Ducktown" });
Yêu cầu "test.php" và chuyển các mảng dữ liệu đến máy chủ (bỏ qua kết quả trả về):
$.get("test.php", { 'colors[]' : ["Red","Green","Blue"] });
Yêu cầu "test.php" và thông báo kết quả của yêu cầu:
$.get("test.php", function(data){
alert("Data: " + data);
});
Cú pháp
$.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:
|