Hi All,

I have a .js file which uses AJAX to query some fields from a DB, and then document.writes a few div's using those fields. I then need to start an interval that calls importantFunction() every 4 seconds. The problem is, I dont know where to place importantFunction(). I have tried the POSSIBLE POSITIONS mentioned in the code below, but all give a "importantFunction not declared" sort of javascript error.

And help would be appreciated.

Code:
function ajaxFunction()
{
  var ajaxRequest;

  try
  {
    ajaxRequest = new XMLHttpRequest();
  }
  catch (e)
  {
    try
    {
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        alert("Your browser broke!");
        return false;
      }
    }
  }

  ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4)
    {
      returnVal = ajaxRequest.responseText;

      for(fd=1; fd<=total; fd++)
      {
        document.write('<div>');
        document.write(fd + ": " + returnVal);
        document.write('</div>');

        //POSSIBLE POSITION 2, USING document.write
        //POSSIBLE POSITION 3, JUST AS A JAVASCRIPT FUNCTION
      }
      document.close();

      var t = setInterval('importantFunction()',4000);
    }
  }

  ajaxRequest.open("GET", "queryDB.php", true);
  ajaxRequest.send(null); 
}

//POSSIBLE POSITION 1

ajaxFunction();