3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jQueryで非同期通信のcallbackの記述方法について(success, error, completeは非推奨)

Last updated at Posted at 2019-04-03

jQueryで非同期通信を書く時には$.ajaxを使いますが、パラメータを覚えられないためテンプレートを投稿しようとして調べていたところ、いつもcallbackに使っていたsuccess, error, completeがdepreciatedになっていたので切り替える必要があることに気づきました。

参照:jQuery API Documentation

今後は.done(), .fail(), .always()を使うそうです。promise的な記述なので今風ですね。

ということで、だいたい使うものは以下になります。

$.ajax({
  type: "POST",
  url: "someurl",
  data: {"some": "parameters"},
  dataType: "json", //結果をjsonで受信する場合
})
.done(function(data) {
  //正常時の処理を記述
})
.fail(function(jqXHR, textStatus, errorThrown) {
  //失敗時の処理を記述
});
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?