jQuery รับ ()เมธอด
ตัวอย่าง
ส่งคำขอ HTTP GET ไปยังหน้าและรับผลลัพธ์กลับ:
$("button").click(function(){
$.get("demo_test.asp", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
ความหมายและการใช้งาน
วิธี $.get() โหลดข้อมูลจากเซิร์ฟเวอร์โดยใช้คำขอ HTTP GET
ตัวอย่าง
ขอ "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:
|