View Single Post
  #1 (permalink)  
Old May 20th, 2009, 06:57 PM
fullingdale fullingdale is offline
Authorized User
Points: 169, Level: 3
Points: 169, Level: 3 Points: 169, Level: 3 Points: 169, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: Northampton, , United Kingdom.
Posts: 35
Thanks: 1
Thanked 0 Times in 0 Posts
Default Multiple, Simultaneous, Asyncronous Requests

I have followed the guides on the net to do this and although the requests seem to work okay, the data returned isn't. My code (below) returns the following text:
Process Start at: 20/05/2009 23:47:51
Wait until: 20/05/2009 23:47:54
Delay value: 3

Process Start at: 20/05/2009 23:47:54
Wait until: 20/05/2009 23:47:57
Delay value: 3
As you can see, the result of the second process started after the first finished, whereas I was hoping for the following result:
Process Start at: 20/05/2009 23:47:51
Wait until: 20/05/2009 23:47:54
Delay value: 3

Process Start at: 20/05/2009 23:47:51
Wait until: 20/05/2009 23:47:54
Delay value: 3
Hopefully someone can point out the error of my ways here.



Client-Side Javascript

Code:
        var sTargetPage = "GetData.asp"

        var xmlhttp = new Array();

        var aSournceKey = new Array();
            aSournceKey[0] = "SOURCE1";
            aSournceKey[1] = "SOURCE2";

        function fetchData()
        {
            for (var i = 0; i < aSournceKey.length; i++)
            {
                xmlhttp[i] = new ActiveXObject("Microsoft.XMLHTTP");
                xmlhttp[i].onreadystatechange = gotArrayData;
                xmlhttp[i].open("POST", sTargetPage, true);
                xmlhttp[i].send("<DATA><SYSTEM>" + aSournceKey[i] + "</SYSTEM></DATA>");
            }

        }

        function gotArrayData()
        {
            for (var i = 0; i < xmlhttp.length; i++)
            {
                if (xmlhttp[i].readyState == 4)
                {
                    if (xmlhttp[i].status == 200)
                    {
                        document.all.item("txtTime" + i).innerHTML = xmlhttp[i].responseText;
                    }
                    else { alert("Problem retrieving data:" + xmlhttp[i].statusText); }
                }
            }
        }
Which points to the Server-Side GetData.asp page, as follows:

Code:
Response.CacheControl = "no-cache"

    Dim xmldom
    
    Dim dDate
    
    Dim nDelayIt
    
    Set xmldom = Server.CreateObject("Microsoft.XMLDOM")
    
        If xmldom.load(Request) then
        
            Select Case xmldom.selectSingleNode("//DATA/SYSTEM").text
            
            Case "SOURCE1"
            
                nDelayIt = 3
            
            Case "SOURCE2"
            
                nDelayIt = 3

            End Select
            
            Response.Write "Process Start at: " & Now & "<br>"

            dDate = DateAdd("s", nDelayIt, Now)
            
            Do While Now < dDate
            
                ' Nothing, but wait!
            
            Loop

            Response.Write "Wait until: " & dDate & "<br>"
            
            Response.Write "Delay value: " & nDelayIt & "<br>"
            
        else
        
            Response.Write "ERROR" & xmldom.parseError.reason & "<br>" & xmldom.xml
        
        end if
    
    Set xmldom = Nothing
__________________
Regards,

Sean