开发者

jquery: auto reload/update page element?

开发者 https://www.devze.com 2023-02-11 08:21 出处:网络
I want to upgrade a specific page element every minute. I know how to use the jq开发者_JAVA技巧uery load() function to reload a element on my page like this.

I want to upgrade a specific page element every minute.

I know how to use the jq开发者_JAVA技巧uery load() function to reload a element on my page like this.

    $('.mostliked').load("http://mypage.com" + " .mostliked >*", function() {
        //callback
    });

That works fine because .mostliked is an element in my sidebar.

However now I need to update a element where I can not grab it's content from some other page like in my sidebar example.

var reload = 60000; setInterval(function() {

    $('ul.rating').each(function() {
        //simply reload this element every minute
    })
    //update sidebar widget
    $('.mostliked').load("http://mypage.com" + " .mostliked >*", function() {
        //callback
    });

}, reload);

How can I solve that problem?


$(document).ready(function() {
                setInterval(function() {
    $(".mostliked").load("http://mypage.com" + " .mostliked","");
}, 60000);
});


Check under the heading "Loading Page Fragments" on this page: http://api.jquery.com/load/

In order to "reload" the ul.rating elements, you will need to fetch the current page in the background (using load or another method), and capture its ul.rating elements and replace them in the page that javascript is running on.

Note: This isn't the best way to do this, it would be much better if you could have some server size code return just the content you need for the ul.rating elements, instead of issuing an entire page request are parsing out the parts you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消