0

I am trying to chain ajax calls: when i load html content in all element i want load it in others. I would want to do without hardcode the calls in each element with closures attached to the local ajax events. I tried to do with global ajax events like so:

$("#elem2").ajaxSuccess(function(e,x,opts) {
  var myUrl="server/elem2"
  if(conditionToAvoidRecursiveCalls)
    $(this).load(myUrl)
})

but i dont get how to define the conditionToAvoidRecursiveCalls: e.target!=this dont work and opts.url!==url dont avoid mutually recursive calls.

Is there another clever way?

4

2 回答 2

1

好吧,解决方案比我想象的要简单,在 ajax 调用中有一个选项已经做了我想要的(全局:false):

var html=$.ajax({url: url,global:false}).responseText
$(this).html(html)

全局布尔默认值:true

是否为此请求触发全局 Ajax 事件处理程序。默认值为真。设置为 false 以防止触发 ajaxStart 或 ajaxStop 等全局处理程序。这可用于控制各种 Ajax 事件。

于 2011-01-21T11:36:33.867 回答
0

使用Ajax 队列插件。它是由 John Resig 自己编写的。

于 2011-01-21T10:22:59.383 回答