在不刷新页面的情况下自动刷新 PHP 请求?

Refreshing a PHP request automatically without refreshing the page?

截至目前,我有一个每 8 秒自动刷新一次的 PHP 页面。刷新时,它会更新从 API 获取的页面信息。如何在不刷新页面的情况下刷新 PHP 脚本 [清除当前 data/html 文本,回显新数据]?提前致谢!

您不能使用 PHP,您需要通过 javascript 提出 ajax 请求。

操作示例:

http://www.w3schools.com/ajax/

创建包含 ajax 代码(javascript 或 jquery)的页面。这里是jqueryajax(很简单)
创建另一个 php 页面并将所有必需的 php 代码放在那里。
所以我们有第 1 页 ajax 和第 2 页 php code

在第 1 页

$.ajax({
  method: "POST",
  url: "yourphppage.php",  //php page link here
  data: { name: "John"}  // send any data to php page if needed
})
  .done(function( msg ) {   //msg contains the response from php page...
    alert( "Data Saved: " + msg );   //use msg to update the page without refresh
  });

现在在第 2 页添加您拥有的 php 代码...第 2 页将 return 响应第 1 页。这就是 ajax 的工作方式,结果是未完全刷新而更新的页面