jQuery的:: ajaxStop()与jQuery的:: ajaxComplete() [英] jquery::ajaxStop() versus jquery::ajaxComplete()

查看:414
本文介绍了jQuery的:: ajaxStop()与jQuery的:: ajaxComplete()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个是在该时间中使用。

Which is to be used at which time.

在上 http://api.jquery.com/ 文档:

有关ajaxStop()这样说的:

For ajaxStop() it says:

说明:注册一个​​处理函数,当所有Ajax请求已完成被调用。这是一个Ajax事件。

Description: Register a handler to be called when all Ajax requests have completed. This is an Ajax Event.

和为ajaxComplete()这样说的:

And for the ajaxComplete() it says:

说明:注册一个​​处理程序时,Ajax请求完全被调用。这是一个Ajax事件。

Description: Register a handler to be called when Ajax requests complete. This is an Ajax Event.

这是我所看到的ajaxComplete(),因为更灵活:

From what I can see ajaxComplete() is more flexible due to:

所有ajaxComplete处理程序被调用,不管是什么Ajax请求完成。如果一定要在请求区分开来,我们可以使用传递给处理程序的参数。当执行处理程序ajaxComplete每次,它是通过事件对象,所述XMLHtt prequest对象,并且设置对象被在创建请求的使用。

All ajaxComplete handlers are invoked, regardless of what Ajax request was completed. If we must differentiate between the requests, we can use the parameters passed to the handler. Each time an ajaxComplete handler is executed, it is passed the event object, the XMLHttpRequest object, and the settings object that was used in the creation of the request.

有人能解释每一个是和合适的用法为每次。在我最近建立了一个应用程序,我靠ajaxStop()时,我的ajax调用完了火。然后,我会解析返回的数据,服务器端操作的结果。现在,我开始我是否应该用ajaxComplete(怀疑),而不是或两者的各种情况的组合。

Can someone explain what each is for and the appropriate usage for each. In an application I built recently I relied on ajaxStop() to fire when my ajax calls were finished. I would then parse the returned data for result of server side operation. Now I am starting to wonder if I should have used ajaxComplete() instead or a combination of both for various situations.

思想是AP preciated。

Thoughts are appreciated.

推荐答案

那么,短版是他们服务于不同的目的,所以答案是选项既对各种情况的组合。其基本规则是:

Well, the short version is they serve different purposes, so the answer would be the "a combination of both for various situations" option. The basic rules are:

  • .ajaxComplete() - 对于每次运行要求是完成时,使用此当你想要做的事与每个请求/结果。请注意,这并不能取代成功处理程序,因为所分析的数据不是一个参数(它运行,即使有错误) - 您可能需要<一个HREF =htt​​p://api.jquery.com/ajaxSuccess/> .ajaxSuccess() 一些每个请求的情况吧。
  • .ajaxStop() - 运行时的每一批请求完成后,通常你会在 .ajaxStart() 喜欢的事情显示/隐藏正在加载...某种指标 - 或做其它的事情,一旦一个批次的AJAX请求完成后,像一个主人最后一步
  • .ajaxComplete() - runs for every request that completes, use this when you want to do something with each request/result. Note that this doesn't replace the success handler, since the parsed data is not one of the arguments (and it runs even when there's an error) - you may want .ajaxSuccess() in some per-request situations instead.
  • .ajaxStop() - runs when every batch of requests completes, usually you'd use this in combination with .ajaxStart() for things like showing/hiding a "Loading..." indicator of some sort - or to do something else once a batch of AJAX requests finishes, like a master last step.

如果你使用这个来分析你的数据,有可能是一个更好的方法,在这种情况下, $ .ajaxSetup() ,在那里你可以指定一个成功处理程序,获取已解析的数据(例如,JSON响应将是对象),是这样的:

If you're using this to parse your data, there's probably a better way, in this case $.ajaxSetup(), where you can specify a success handler that gets the already-parsed data (e.g. JSON responses will be objects), like this:

$.ajaxSetup({
  success: function(data) { 
    //do something with data, for JSON it's already an object, etc.
  }
});

这篇关于jQuery的:: ajaxStop()与jQuery的:: ajaxComplete()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆