Jquery checking success of ajax post

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

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

5条回答
  •  隐瞒了意图╮
    2020-11-27 15:54

    The documentation is here: http://docs.jquery.com/Ajax/jQuery.ajax

    But, to summarize, the ajax call takes a bunch of options. the ones you are looking for are error and success.

    You would call it like this:

    $.ajax({
      url: 'mypage.html',
      success: function(){
        alert('success');
      },
      error: function(){
        alert('failure');
      }
    });
    

    I have shown the success and error function taking no arguments, but they can receive arguments.

    The error function can take three arguments: XMLHttpRequest, textStatus, and errorThrown.

    The success function can take two arguments: data and textStatus. The page you requested will be in the data argument.

提交回复
热议问题