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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.