简体   繁体   English

是否有一个只刷新PHP脚本的jQuery函数?

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

I'm new to AJAX, jQuery, etc. 我是AJAX,jQuery等的新手。

But is there a function that will just auto-refresh a PHP script? 但是有一个函数只会自动刷新PHP脚本吗?

If you wanted to execute a javascript function at regular intervals you cold use the window.setInterval function: 如果你想定期执行一个javascript函数,你可以使用window.setInterval函数:

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: 所以你可以编写一个函数来向你的PHP脚本发送一个AJAX请求:

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(); 或者如果你想重新加载整个页面(不使用AJAX),你可以使用window.location.reload();

You don't need jQuery, just plain old Javascript. 你不需要jQuery,只需要简单的旧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. 如果这是您需要的话,请与window.setTimeout结合使用,以便在延迟一段时间后执行此操作。

See docs for: 查看文档:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM