0

Hi All,

the following code is used to get an update from a database. My question is how can I use this more than once on a page to call two different queries (from different php files)?

<html>
<head>
<script type="text/javascript">
function showHint(str)
{
  if (window.XMLHttpRequest)
    xmlhttp = new XMLHttpRequest();
  else
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

  xmlhttp.onreadystatechange = function()
  {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
      document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
  };
  xmlhttp.open("GET", "console4.php" + str, true);
  xmlhttp.send(null);
}
</script>
</head>
<body>
<script type="text/javascript">showHint(this.value)</script>

<p><span id="txtHint"></span></p> 
</body>
</html>

      <script type="text/javascript">
      function keepCalling() {
      showHint("");
      window.setTimeout("keepCalling()", 2000) ;// call the showHint every (2)000 second
      }
      keepCalling();
      </script>
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by pritaeas
0

I would extend the function showHint to accept two more parameters: the first being the php file to call, and the second the elementId to update. That way you can keep using the same function.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.