且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP 代码只在 javascript setInterval 中运行一次

更新时间:2023-02-25 15:13:38

基本上,当您在 javascript 中编写 php 代码时,它总是在页面加载时运行一次.之后你只是写php代码到浏览器根本看不懂(Php在服务器端处理,输出的是Html、Css和Javascript,浏览器可以解释)

Basically when you write php code inside javascript, it always run once, when the page is loaded. After this you just writing php code to the browser which is simply do not understand (Php is processed on the server, and the output is Html, Css, and Javascript, which the browser can interpret)

因此,如果您需要在不重新加载页面的情况下从服务器更新数据,唯一的方法是使用 Ajax 请求,它基本上连接到页面内的服务器并从中获取数据.

So, if you need to update data from the server without reloading the page, the only way to do this is with Ajax Requests, that basically connect to the server within the page and get data from it.

有关 Ajax 的更多信息:Ajax 基础知识

more on Ajax: Ajax Basics