error handling with .post()

前端 未结 3 840
囚心锁ツ
囚心锁ツ 2021-01-31 13:50

I have to modify a project written by someone else. Because the code is a mess I can\'t really change this $.post() (or replace it by $.ajax()). What I need to do, is to know if

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-31 14:30

    Define the error callback immediately after the post. Note the semi-colon placement only at the end.

    $.post('balbal.html', json, function(data) {
        // ... my code ...
    })
    .fail(function(response) {
        alert('Error: ' + response.responseText);
    });
    

    http://api.jquery.com/deferred.fail/

    For older versions of jQuery (pre-1.8) Use .error instead with the same syntax.

提交回复
热议问题