简体   繁体   中英

jQuery .live() on JS function - What event to use?

I'm trying to have a setInterval function to use .live() to get information from dynamic content loaded with AJAX. Here's what I have.

var auto_refresh = setInterval(
    function () { 
       var msgid = $(".msgid:last").attr("id");
       alert (msgid);
    }, 5000);

Obviously this does not work on content that is loaded with AJAX. I can't seem to find any event that could be used for the live() function in this case. All I need is to fetch the last msgid that is loaded on the page every 5 seconds.

Any advice?

Thank you in advance.

As the guys mentioned as comments, your code seems to work, so I can only assume that you want a different way to handle it, perhaps something a little more 'jquery-esque'?

If all your requests are similar, and you know how to parse the response, you could try having a global handler...

$('body').ajaxSuccess(function(e,x,o) {
    console.log(e);
    console.log(x);
    console.log(o);
})

as seen on the jquery website

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