Jump to content

Make things appear without refreshing...


pyro.699

Recommended Posts

There are a couple of ways to do this, but I suspect they are using a xmlhttp request.Like the one here, you could arrange a request that checks a status condition:XMLHTTP RequestThe Mozilla site has an article and examples here:Ajax:Getting StartedYou should be able to do a view source on the page you are referring to and get an idea.

Link to comment
Share on other sites

Adapting the code from this example:HTTP RequestWe can set a timeout and call a php page, this page happens to read the url value.But you could open a file and read a line.status.php

<?phpheader('Content-type: text/xml');$counter = 0;if(isset($_GET['cycle']))$counter = intval($_GET['cycle']);function txMsg(){global $counter;  if($counter < 10) {echo '<?xml version="1.0" encoding="ISO-8859-1"?><span id="status">We have requested an update '. $counter .' times.</span>';  }else {echo '<?xml version="1.0" encoding="ISO-8859-1"?><span id="status">Whatever it was, it\'s done...</span>';  }}txMsg();?>

getStatus.html

<html><head><style type="text/css">span {color: #66ff66;background-color: #000000;font: bold 1em arial;}</style><script type="text/javascript">var xmlhttp;var cycle = 0;function getStatus(){var url = 'status.php?cycle=' + (cycle++);// code for Mozilla, etc.if (window.XMLHttpRequest)  {  xmlhttp=new XMLHttpRequest();  xmlhttp.onreadystatechange=state_Change;  xmlhttp.open("GET",url,true);  xmlhttp.send(null);  }// code for IEelse if (window.ActiveXObject)  {  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");    if (xmlhttp)    {    xmlhttp.onreadystatechange=state_Change;    xmlhttp.open("GET",url,true);    xmlhttp.send();    }  }}function state_Change(){// if xmlhttp shows "loaded"if (xmlhttp.readyState==4)  {  // if "OK"  if (xmlhttp.status==200)  {  document.getElementById('A1').innerHTML=xmlhttp.responseText;  if(cycle <= 10) setTimeout('getStatus()', 1000);  }  else  {  alert("Problem retrieving XML data:" + xmlhttp.statusText)  }  }}setTimeout('getStatus()', 1000);</script></head><body><h2>Using the HttpRequest Object</h2><p><b>status:</b><span id="A1">Initializing</span></p></body></html>

Hopefully this will give you an idea, :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...