weixin_33712987 2013-04-09 20:05 采纳率: 0%
浏览 27

针对特定事件的ajaxStop

I read this question but it did not help much because of success:function. it do not understand completion of Ajax response. Do anyone know how to use Ajax stop for specific events ?

Detail : I have an Ajax code which sends a request and I want it to do something when it gets a response. I do that by the following function but it gets all documents of Ajax and I cant add any Ajax to the page.

$(document).ajaxStop(function() {
                ....;
                alert("start");
});
  • 写回答

1条回答 默认 最新

  • 普通网友 2013-04-09 20:13
    关注

    ajaxStop is meant to be used for a global AJAX completion behavior. You probably want to use a regular complete handler:

    $.ajax({
      url: "some/path.php",
      complete: function() { alert("start"); }
    });
    

    or alternatively you can use the always promise method:

    $.ajax({
      url: "http://fiddle.jshell.net/favicon.png",
    }).always(function() {
      alert("start");
    });
    

    UPDATE:

    Looking at your comments below, you might actually want to use success (especially when you are interested in the response:

    $.ajax({
      url: "some/path.php",
      success: function(response) { alert(response); }
    });
    

    or alternatively you can use the done promise method:

    $.ajax({
      url: "http://fiddle.jshell.net/favicon.png",
    }).done(function(response) {
      alert(response);
    });
    

    However, it is important to note that both of those methods only execute when you receive a successful response from the server (status code 200).

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?