开发者

Is there an jQuery function that will just refresh a PHP script?

I'm new to AJAX, 开发者_Go百科jQuery, etc.

But is there a function that will just auto-refresh a PHP script?


If you wanted to execute a javascript function at regular intervals you cold use the window.setInterval function:

window.setInterval(function() {
    // this method will execute on every 5 seconds
}, 5000);

So you could write a function that will send an AJAX request to your PHP script:

window.setInterval(function() {
    // replace the contents of an element with id="res" 
    // every 5 seconds by the result of the PHP script
    $('#res').load('/foo.php');
}, 5000);

Or if you want to reload the entire page (without using AJAX) you could use window.location.reload();


You don't need jQuery, just plain old Javascript.

window.location.reload()

should reload the current page. Combine with window.setTimeout to do it after some delay if that's what you need.

See docs for:

  • window.location
  • window.setTimeout
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜