jQuery ajaxError() Metode

Metode jQuery AJAX

Contoh

Memicu kotak peringatan ketika permintaan AJAX gagal:

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

Definisi dan Penggunaan

Metode ajaxError() menentukan fungsi yang akan dijalankan ketika permintaan AJAX gagal.

Catatan: Pada jQuery versi 1.8, metode ini hanya boleh dilampirkan ke dokumen.


Sintaksis

$(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

Cobalah Sendiri - Contoh


Cara menggunakan parameter opsi untuk mendapatkan pesan kesalahan yang lebih berguna.


Metode jQuery AJAX