开发者

How can I reload webpage when another user edits it?

I have an app where items can be edited by multiple users. When someone edits an item the other people have to reload the page to see t开发者_开发知识库he changes. How can I know when someone edits an item so that I can refresh the item for other people.

So say Bob is in florida and edits an item on the website. Jill in seattle doesn't see the change until she reloads the page. How can I refresh Jill's item when Bob edits it?

I'm using rails, jquery, postgresql on heroku.

EDIT: If a page has 200 items I'd rather not check constantly to see if each of them has changed.


You have to either request server periodically with $.ajax to check if the item was modified after page load, or use comet


What you are talking of is known as Ajax (asynchronous javascript) which has the ability to send and receive packets from the server without reloading the page. Fortunately for you, rails has a built-in ability for AJAX. I find this to be a very good tutorial. Also, I cannot find it at the moment, but there is a very good screencast that shows one how to make a blog with ruby on rails, and it also covers AJAX.


You can make a script which returns "1" when the page has changed and "0" when it hasn't. Then you do something like this with jquery:

setInterval(function() {
    $.ajax({
        'url': 'url_to_check',
        'method': 'GET',
        'data': {
            'pageid': pageidhere
        },
        'success':function(data) {
            if (data == '1') {
                location.reload();
            }
        }
    });
}, 5000);

where url_to_check is the url of the script which checks if a certain pageid has to be reloaded. The 5000 stands for "check again every 5 seconds"


You can start playing around jquery ajax , which is really powerful

http://api.jquery.com/jQuery.ajax/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜