Jquery checking success of ajax post

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

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

5条回答
  •  广开言路
    2020-11-27 15:39

    If you need a failure function, you can't use the $.get or $.post functions; you will need to call the $.ajax function directly. You pass an options object that can have "success" and "error" callbacks.

    Instead of this:

    $.post("/post/url.php", parameters, successFunction);
    

    you would use this:

    $.ajax({
        url: "/post/url.php",
        type: "POST",
        data: parameters,
        success: successFunction,
        error: errorFunction
    });
    

    There are lots of other options available too. The documentation lists all the options available.

提交回复
热议问题