简体   繁体   中英

jquery timing with ajax call and html()

I am loading a list into a div via perl in an ajax call. 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.

To test this I wrapped the trigger line in a setTimeout of 1000 it worked fine. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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