开发者

How I can change the content of my site's page after a couple of minutes?

So, I need to chang开发者_开发百科e the data representation after a couple of minutes since user did something (e.g. uploaded an image)

What I need is to change some div in page after some time? How I can do it? What to use like a tool? PHP or JavaScript?

Thanks, But how does imgur do it after image upload?


You could take a look at ajax, and use that so the image is uploaded, and then displayed, or, you can use it to make calls to a page every x seconds, whatever takes your fancy.


You'll have to use JavaScript for this. An example is this:

function timeout_trigger() {
    window.alert('Hello!');   
}

function timeout_init() {
    setTimeout('timeout_trigger()', 120000); // 2 minutes
}

setTimeout uses miliseconds. So 1 minute is 60.000.

Call the timeout_init() function on an event you like. So could be done onclick


You'd need to use Ajax. Here's an example of how to use Ajax with Jquery:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript">
    $(function() {
        setInterval('load_stuff()', (1000 * 60 * 60 * 2)); // 2 minutes
    });
    function load_stuff() {
        $.ajax({
            url : 'http://www.yourdomain.com/ajax.php', 
            success:function(data) {
                $('div#reload_conent').html(data);
            }
        });
    }
</script>

Read more here about ajax.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜