Jquery checking success of ajax post

前端 未结 5 1843
庸人自扰
庸人自扰 2020-11-27 15:30

how do i define the success and failure function of an ajax $.post?

5条回答
  •  没有蜡笔的小新
    2020-11-27 15:44

    using jQuery 1.8 and above, should use the following:

    var request = $.ajax({
        type: 'POST',
        url: 'mmm.php',
        data: { abc: "abcdefghijklmnopqrstuvwxyz" } })
        .done(function(data) { alert("success"+data.slice(0, 100)); })
        .fail(function() { alert("error"); })
        .always(function() { alert("complete"); });
    

    check out the docs as @hitautodestruct stated.

提交回复
热议问题