jQuery load()วิธี การ

❮ วิธีการ jQuery AJAX

ตัวอย่าง

โหลดเนื้อหาของไฟล์ "demo_test.txt" ลงในองค์ประกอบ <div> เฉพาะ:

$("button").click(function(){
  $("#div1").load("demo_test.txt");
});

ความหมายและการใช้งาน

Load() วิธีการโหลดข้อมูลจากเซิร์ฟเวอร์และนำข้อมูลที่ส่งกลับเข้าไปในองค์ประกอบที่เลือก

หมายเหตุ:นอกจากนี้ยังมีวิธี jQuery Eventที่เรียกว่าการโหลด อันไหนเรียกว่าขึ้นอยู่กับพารามิเตอร์


ไวยากรณ์

$(selector).load(url,data,function(response,status,xhr))

Parameter Description
url Required. Specifies the URL you wish to load
data Optional. Specifies data to send to the server along with the request
function(response,status,xhr) Optional. Specifies a callback function to run when the load() method is completed.

Additional parameters:
  • response - contains the result data from the request
  • status - contains the status of the request ("success", "notmodified", "error", "timeout", or "parsererror")
  • xhr - contains the XMLHttpRequest object

ลองด้วยตัวคุณเอง - ตัวอย่าง


วิธีใช้พารามิเตอร์ข้อมูลเพื่อส่งข้อมูลด้วยคำขอ AJAX (ตัวอย่างนี้ใช้ตัวอย่างที่อธิบายไว้ใน บทช่วย สอน AJAX ของเรา )


วิธีใช้พารามิเตอร์ฟังก์ชันเพื่อทำงานกับผลลัพธ์ข้อมูลจากคำขอ AJAX


วิธีใช้พารามิเตอร์ฟังก์ชันเพื่อจัดการกับข้อผิดพลาดในคำขอ AJAX (โดยใช้พารามิเตอร์ XMLHttpRequest)


❮ วิธีการ jQuery AJAX