为何取不出正确的的文件内容
我有三个文件,分别是1.php、2.php和Ajax.js
1.php内容如下
$i= //对变量i进行一系列运算
include("2.php")
2.php内容如下
echo $i;
Ajax.js大体内容如下:
每隔1秒中请求一下2.php的返回内容;
httpxml.open("get","2.php");
XX.innerHTML=httpxml.responseText;
但是现在的问题是XX.innerHTML始终不变,不知为何?
已确认以下信息:
1、1.php中的$i内容时刻在变化
2、Ajax.js也按照规定频率执行请求动作
回复讨论(解决方案)
httpxml.open("get","2.php?t="+Math.random()); //请求地址加个随机数看看
httpxml.open("get"," 1.php");
2.php 只是输出 1.php 计算的结果
加随机数是没有问题的,能体现效果
2楼版主,请问问题在哪呢
不是说了吗?
那么你只访问2.php如何能得到1.php计算的结果呢?
提醒下,在1.php中,是在$i时刻变化的过程中执行include("2.php")的
呵呵,很感谢提醒。但是被提醒的应该是你
你 httpxml.open("get","2.php"); 访问的是 2.php !
而2.php中并没有数据计算
但是 2.php 里有获取变量$i啊?此变量来自1.php的计算
1.php和2.php里$i指的应该是同一变量吧,因为1.php里有include.不知我的理解可对
你确认直接调2.php能获得$i的值?
但是 2.php 里有获取变量$i啊?此变量来自1.php的计算
这么看还是拿出你的详细一些的代码,看一下吧~
不是页面缓存么?
老徐说的很清楚了吧 是1包含了2 你要请求1才能得到结果。。。。没理解include吧
我还是贴出来吧。最终想实现一个Ajax的例子,共4个文件,分别是form.php,1.php,2.php,Ajax.js
form.php内容如下:
<script></script>
1.php内容如下:
session_start();
for ($i;$i {
$_SESSION["temp"]=$i;
sleep(1);
}
?>
2.php内容如下:
session_start();
echo $_SESSION["temp"];
Ajax.js内容如下:
function createRequestObject() {
var http;
if (navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
http = new XMLHttpRequest();
}
return http;
}
function sendRequest() {
var http = createRequestObject();
http.onreadystatechange = function () { handleResponse(http); };
http.send(null);
}
function handleResponse(http) {
var response;
if (http.readyState == 4) {
response = http.responseText;
http.open("GET", "2.php");
document.getElementById("status").innerHTML = response;
if (response setTimeout("sendRequest()", 1000);
}
else {
document.getElementById("status").innerHTML = "Done.";
}
}
}
function startUpload() {
setTimeout("sendRequest()", 1000);
}
document.getElementById("myForm").onsubmit = startUpload;
我想实现的效果是在form里点击“生成报表”按钮,则会每一秒钟显示一个从0到9的数字。
请高手帮助分析下原因,现在点击“生成报表”按钮后未有数字每隔1秒显示出来
有哪位高手指点下?
我知道你想做什么了(上传进度条)
那么对不起,你走进死胡同了
对于上传进度条,php提供了arc和upload两个扩展,并且php5.4也内置了类似功能
如何写?你搜索一下就知道了
你的应用不可能实现的原因在于默认的文件方式的 session
session 临时文件一旦被打开,就不能被其他进程再打开了
对于其他存储方式是否也是这样,没有测试过不好乱说
版主,我确实想实现类似进度条的功能,但是不是文件上传的进度条。(文件上传进度条的实现方式我已了解)
我想实现的是用Ajax获取1.php文件处理过程的进度(因为1.php是一个比较漫长的过程,可能需要几十秒钟,我想通过Ajax的方式将1.php的处理进度实时的展现给用户)
除了 seeeion,你就不能用其他共享手段传递数据吗?
我是菜鸟,请版主指教
难道没有人会么
哎。用数据库共享数据了

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...
