Jump to content

Question: How often does PHP send an echo back to JavaScript?


bobleny

Recommended Posts

I have a script that looks much like this...

 

index.php

<html>
<head>
	<script type="text/javascript">
		<!--
			var GetServer
			function Connect()
			{
				try
				{
					// Firefox, Opera 8.0+, Safari
					GetServer = new XMLHttpRequest();
				}
				catch (e)
				{
					// Internet Explorer
					try
					{
						GetServer = new ActiveXObject("Msxml2.XMLHTTP");
					}
					catch (e)
					{
						try
						{
							GetServer = new ActiveXObject("Microsoft.XMLHTTP");
						}
						catch (e)
						{
							return false;
						}
					}
				}
			}

			function Check()
			{
				Connect();

				GetServer.onreadystatechange=function()
				{
					if(GetServer.readyState == 4)
					{
						document.getElementById("echo").innerHTML = GetServer.responseText;
						Retrieve();
					}
				}

				var site = "page_2.php";
				GetServer.open("GET",site,true);
				GetServer.send(null);
			}

			Check();
		-->
	</script>
</head>
<body>
	<span id="echo"></span>
</body>
</html>

 

 

page_2.php

<?php
echo "foo<br />";
sleep(60);
echo "fooy";
?>

 

 

OK, this script should echo foo, wait 1 minute, and echo fooy; in that order. But that's not what it does, it waits 1 minute, then echos foo and fooy at the same time.

 

 

Is there a way to make it echo foo, wait 1 minute, and then echo fooy?

Link to comment
Share on other sites

well as per my knowlegde ajax waits for the script to finish execution so when it does it will give you both the variables,what your looking for should be two scripts governed by javascript not php so the first script you call echos foo and the second one you call echos fooy so you have to have the sleep in javascript not php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.