I have three files, 1.php, 2.php and Ajax.js, respectively.
1.php content is as follows
$i =//A series of operations on variable i
Include ("2.php")
2.php content is as follows
echo $i;
Ajax.js general content is as follows:
Request the return content of 2.php every 1 seconds;
Httpxml.open ("Get", "2.php");
Xx.innerhtml=httpxml.responsetext;
But now the problem is that xx.innerhtml is always the same, and I don't know why?
The following information has been confirmed:
1, the $i content of 1.php in the moment changes
2, Ajax.js also perform the request action according to the specified frequency
Reply to discussion (solution)
Httpxml.open ("Get", "2.php?t=" +math.random ()); Request an address, add a random number, see.
Httpxml.open ("Get", "1.php");
2.php is just the result of the output 1.php calculation
Plus the random number is no problem, can reflect the effect
2 floor Moderator, may I ask the question?
Didn't you say it?
So how can you only access 2.php to get the results of 1.php calculations?
As a reminder, in 1.php, the include ("2.php") is executed during the $i time change
Oh, thank you very much for reminding me. But you're supposed to be reminded.
You Httpxml.open ("Get", "2.php"); The Access is 2.php!
And there is no data calculation in 2.php
But is there a variable $i in 2.php? This variable is calculated from the 1.php
1.php and 2.php $i refer to the same variable, because 1.php has an include. I don't know what I understand.
Do you confirm that the direct 2.php can get $i value?
But is there a variable $i in 2.php? This variable is calculated from the 1.php
So look at it or take out your detailed code, look at it ~
Not a page cache?
Lao Xu said very clearly is 1 contains 2 you have to request 1 to get results .... I don't understand the include.
I'll stick it out. Finally want to implement an Ajax example, a total of 4 files, respectively, is form.php,1.php,2.php,ajax.js
form.php content is as follows:
The 1.php content is as follows:
Session_Start ();
for ($i; $i <10; $i + +)
{
$_session["temp"]= $i;
Sleep (1);
}
?>
The 2.php content is as follows:
Session_Start ();
echo $_session["temp"];
Ajax.js content is as follows:
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 < 100000000000000000) {
SetTimeout ("SendRequest ()", 1000);
}
else {
document.getElementById ("status"). InnerHTML = "done.";
}
}
}
function Startupload () {
SetTimeout ("SendRequest ()", 1000);
}
document.getElementById ("MyForm"). onsubmit = Startupload;
The effect I want to achieve is to click the Generate Report button in the form and a number from 0 to 9 is displayed every second.
Please help the expert to analyze the reason, now click "Generate Report" button, no number appears every 1 seconds
Is there any expert pointing down?
I know what you want to do. (Upload progress bar)
So sorry, you're in a dead end.
For the Upload progress bar, PHP provides two extensions for arc and upload, and php5.4 has a similar feature built-in
How to write? You'll find out if you look.
The reason your app is unlikely to be implemented is the default file-mode session
Once the session temp file is opened, it cannot be opened by another process.
Whether it's the same with other storage methods, no tests, no bad chatter.
Moderator, I do want to implement similar progress bar functionality, but is not a file upload progress bar. (The way the file upload progress bar is implemented I know)
What I want to achieve is to use Ajax to get the progress of the 1.php file processing (because 1.php is a lengthy process that may take a few 10 seconds and I want to present the 1.php processing progress in real time to the user via Ajax)
In addition to Seeeion, can you use other sharing methods to pass data?
I am a rookie, please advise the moderator
Isn't anybody going to do that?
Hey. Sharing data with a database