Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Anyone can tell me how to activate two (or more) JavaScript AJAX functions in parallel?
Posted

If you call HttpRequestObject with Async mode, you can easily call any other method while the server request comes.

The readyStatechanged callback you specify will automatically be called back when AJAX request is successfully fetched by the object.

See this
AJAX Tutorial[^]

:cool:
 
Share this answer
 
XML
hi,

thanks for the valued replay,
based upon your link " AJAX Tutorial[^] " that functions is working when the user click the application one by one , and also the ajax is working one after other

---------------------------------------------------------------------
Below is the code in my asp page

Ajax.asp

<html> 
 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
<title>Ajax.asp</title> 
<script type="text/javascript"> 
function Delay(SECOND) 
{ 
var xmlHttp; 
try 
  {   
  xmlHttp=new XMLHttpRequest();  } 
catch (e) 
  {  
   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;  
           }     
           }  
            } 
  xmlHttp.onreadystatechange=function() 
    { 
    if(xmlHttp.readyState==4) 
      {  
    alert(xmlHttp.responseText);      
      } 
    }    
    xmlHttp.open("GET","Delay_Page.asp?SECOND="+SECOND,true); 
    xmlHttp.send(null);  
    return true 
   } 
</script> 
</head> 
 
<body> 
 
// below is the button for passing seconds  
 
<input onclick="javascript:return (Delay('30')&& Delay('10')&& Delay('5'));" type="button" value="Button" name="B3"> 
</body> 
 
</html> 
In the Delay_Page.asp this is the code

<% 
ss= request.querystring("SECOND") 
 
Sub Delay(DelaySeconds) 
SecCount = 0 
Sec2 = 0 
While SecCount < DelaySeconds + 1 
Sec1 = Second(Time()) 
If Sec1 <> Sec2 Then 
Sec2 = Second(Time()) 
SecCount = SecCount + 1 
End If 
Wend  
End Sub 
 
Delay(SECOND) 
 
response.write SECOND &" SECONDS left" 
%> 
The above code is working fine, but some problems i wants to solve

what i need is 

i want to invoke Delay('30')&& Delay('10')&& Delay('5')) functions parallel

Now the condition is, when the first function finish Delay('30') then after only it goes to the second function

Now Total time to finish the function is 45 seconds (30 + 10 + 5)

I need to finish these three functions in 30 seconds , that means all functions need to work in same time 

hoping your help plz,
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900