简体   繁体   English

带ajax调用和html()的jQuery计时

[英]jquery timing with ajax call and html()

I am loading a list into a div via perl in an ajax call. 我在ajax调用中通过perl将列表加载到div中。 Once the list is loaded I am triggering a click on the first row: 加载列表后,我触发了对第一行的单击:

success: function(data) {
  $('#newsList').html(data);
  $("#newsList .EDITrow").first().trigger('click');
},

But the problem is the timing ... in the code above nothing happens. 但是问题是时间问题……在上面的代码中什么也没有发生。

html() is a synchronous operation so I guessed that it wasn't loaded in time for the trigger to do it's job. html()是一个同步操作,因此我猜想触发器没有及时加载它来完成它的工作。

To test this I wrapped the trigger line in a setTimeout of 1000 it worked fine. 为了测试这一点,我将触发行包装在setTimeout为1000中,效果很好。 ie the first row was clicked and everything associated with the click worked as it should. 也就是说,单击第一行,与该单击相关联的所有内容均应正常工作。

As there is not callback for html(), what is the correct way to do this ... clearly the timeout is not the correct way of course. 由于没有html()的回调,执行此操作的正确方法是什么……显然,超时当然不是正确的方法。

尝试使用$("#newsList .EDITrow").delay(1000).first().trigger('click');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM