Hey all,
I have a little Arduino board that is hosting a couple web pages. From the main page, I get information from the board to the page using a periodic ajax call like this...

Code:
function ajaxRequest()
{    
    //create the request
    var request = new XMLHttpRequest();
    request.onreadystatechange = function()
    {    
        if (request.readyState==4 && request.status==200 && request.responseXML!=null)
        {    //we got the good stuffs...    
            //parse it out...
            parseAJAX(request.responseXML);
        }    
    }//done with the callback        
    //send a new request...
        
    var requestString=(AJAX_HEADER + "&" + Math.random());
    request.open("GET",requestString,true);
    request.send();
    //set the refresh...
    setTimeout("ajaxRequest()",1000);    
}
This works fine.

On the page I also have a button. When the user clicks it, I need to send information back to the server. So I need to send a periodic ajax request and I need to send a request on demand (asyncronously if you will).

What is the preferred method of doing this? Is it to create a new request within the button's onClick handler, or should I inject the users request into the periodic request stream?

i am current injecting the request like this, but I'm not sure if it's the right way to do it. Any insight would be appreciated.

Code:
var ajaxRequestString ="";
        function ajaxRequest()
{    
    //create the request
    var request = new XMLHttpRequest();
    request.onreadystatechange = function()
    {    
        if (request.readyState==4 && request.status==200 && request.responseXML!=null)
        {    //we got the good stuffs...    
            //parse it out...
            parseAJAX(request.responseXML);
        }    
    }//done with the callback        
    //send a new request...
        
    var requestString=(AJAX_HEADER + ajaxRequestString + "&" + Math.random());
    request.open("GET",requestString,true);
    request.send();
    //set the refresh...
    setTimeout("ajaxRequest()",1000);    
    ajaxRequestString="";


}    
function button_OnClick()
{
    var x= document.getElementById("x").value;
    var y= document.getElementById("y").value;    
    ajaxRequestString="&x=" + x+ "&y=" + y;
}
Thanks
Kevin