Jump to content

Just trying to do 2 asynchronys ajax calls, WTH


sethi

Recommended Posts

I am just trying to have two ajax requests spit out info from mysql entries every couple of seconds or so... the data to show is lightweight so nothing to worry about there. However, I have looked all the eff over for a difinitive explanation of a simple way to do asynchronys ajax calls that are timed, and just deliver... no interation required... This is the code i have... and i get nothing at all... when i had just one call(gm.php), it worked great.

 

What in the heck am i doing wrong... thanksthanksthanks if you can help me.

 

gm.js

function getXMLHttp()

{

  var xmlHttp

 

  try

  {

    //Firefox, Opera 8.0+, Safari

    xmlHttp = new XMLHttpRequest();

  }

  catch(e)

  {

    //Internet Explorer

    try

    {

      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");

    }

    catch(e)

    {

      try

      {

        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

      }

      catch(e)

      {

        alert("Your browser does not support AJAX!")

        return false;

      }

    }

  }

  return xmlHttp;

}

 

function gm()

{

    xml1 = getXMLHttp();

    xml2 = getXMLHttp();

 

    xml1.onreadystatechange = function()

  {

    if(xml1.readyState == 4)

    {

      handleResponse1(xml1.responseText);

    }

  }

    xml2.onreadystatechange = function()

  {

    if(xml2.readyState == 4)

    {

      handleResponse2(xml2.responseText);

    }

  }

    xml1.open('GET', 'gm.php', true);

    xml2.send(null);

    xml2.open('GET', 'status.php', true);   

    xml1.send(null);

    setTimeout("gm()",6000);

}

function handleResponse1(response)

{

document.getElementById('rd').innerHTML = response;

}

function handleResponse2(response)

{

document.getElementById('status').innerHTML = response;

 

}

Link to comment
Share on other sites

Hi,

 

First try this

 

You have this in code

 

xml1.open('GET', 'gm.php', true);

    xml2.send(null);

    xml2.open('GET', 'status.php', true);   

    xml1.send(null);

 

change it to

xml1.open('GET', 'gm.php', true);

    xml1.send(null);

    xml2.open('GET', 'status.php', true);   

    xml2.send(null);

 

If this not works try to use two variables instead one xmlHttp.

 

Hope this helps you out

 

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.