jQuery ajaxError()เมธอด

❮ วิธีการ jQuery AJAX

ตัวอย่าง

ทริกเกอร์กล่องแจ้งเตือนเมื่อคำขอ AJAX ล้มเหลว:

$(document).ajaxError(function(){
  alert("An error occurred!");
});

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

ajaxError() วิธีการระบุฟังก์ชันที่จะเรียกใช้เมื่อคำขอ AJAX ล้มเหลว

หมายเหตุ:สำหรับ jQuery เวอร์ชัน 1.8 วิธีนี้ควรแนบมากับเอกสารเท่านั้น


ไวยากรณ์

$(document).ajaxError(function(event,xhr,options,exc))

Parameter Description
function(event,xhr,options,exc) Required. Specifies the function to run if the request fails
Additional parameters:
  • event - contains the event object
  • xhr - contains the XMLHttpRequest object
  • options - contains the options used in the AJAX request
  • exc - contains the JavaScript exception, if one occurred

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


วิธีใช้พารามิเตอร์ options เพื่อรับข้อความแสดงข้อผิดพลาดที่เป็นประโยชน์มากขึ้น


❮ วิธีการ jQuery AJAX