jQuery.ajax : fail(jqXHR, textStatus, errorThrown)


jQuery.ajax : fail

jQuery の $.ajax による非同期通信は、レガシーな開発対象では大変有用です。

エラーハンドリングの必要性を考慮し .fail に渡ってくる引数と、その内容を実装ベースで調べました:

.fail(function(jqXHR, textStatus, errorThrown) {
  // jqXHR
  //  .status: 500
  //  .statusText: "Internal Server Error"
  //  .responseJSON: {
  //    "StatusCode": 500,
  //    "Message": "Something went horribly, horribly wrong while servicing your request.",
  //    "Details": "Nancy.RequestExecutionException: Oh noes! ---> System.NullReferenceException: オブジェクト参照がオブジェクト インスタンスに設定されていません。\r\n   場所 ..."
  //  }
  //  .responseText: "{"StatusCode":500,"Message":"Something went horribly, horribly wrong while servicing your request.","Details":"Nancy.RequestExecutionException: Oh noes! ---> System.NullReferenceException: オブジェクト参照がオブジェクト インスタンスに設定されていません。\r\n   場所 ..."
  //  .getAllResponseHeaders(): "cache-control: no-store, no-cache, must-revalidate\r\nconnection: close\r\ncontent-type: application/json; charset=utf-8\r\ndate: Tue, 30 Jun 2020 05:02:13 GMT\r\nexpires: Thu, 19 Nov 1981 08:52:00 GMT\r\nlink: </add-addr.xml>; rel=\"application/xml\"\r\npragma: no-cache\r\nserver: Apache/2.4.41 (Win32) mod_fcgid/2.3.10-dev\r\ntransfer-encoding: chunked\r\nvary: Accept\r\nx-powered-by: PHP/7.4.2\r\n"
  // textStatus: "error"
  // errorThrown: "Internal Server Error"
});
  • jqXHR は略称とのことで (The jQuery XMLHttpRequest (jqXHR) object) XMLHttpRequest オブジェクトのスーパーセットとの説明があります (a superset of the browser's native XMLHttpRequest object.)
  • textStatuserrorThrown は、両方とも string でした。

参考: