30
24

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.

AJAXのコールバック呼び出し順序

Last updated at Posted at 2016-01-13

jquery1.8からsuccessとかerrorとかcompleteとかが非推奨となったらしい。
書き方まとめるついでに、呼び出し順をメモ。
こんなajaxの場合。

    $.ajax({ type: 'post',
        url: 'appmigration/test.json',
        data: [{'key': 'hoge'}], // {'name': 'key', 'value': 'hoge'} とも書ける
        dataType: 'json',
        beforeSend: function() {
            alert('before');
        },
        statusCode: {
            200: function() {
                alert('200');
            },
            400: function() {
                alert('400');
            }
        }
    }).done(function(data){
        alert('done');
    }).fail(function(data){
        alert('fail');
    }).always(function(data){
        alert('always');
    });

before -> done -> always -> 200となる。

30
24
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
30
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?