开发者

How to invoke three ajax functions together?

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 De开发者_JAVA百科lay_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 together

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

hoping your help plz,


I can't really see where your problem is, so it must be in your asp page. I'm sorry to say that I can't have a way of testing asp at the moment, so I can't help there. but, I wrote a fake delay in PHP and run your javascript. Here's what I used to test:

<?
if (isset($_GET['SECOND'])) {


    for($i=0;$i<$_GET['SECOND']*100000;$i++) {
        $x = sqrt($i);
    }
    echo $_GET['SECOND'].': x='.$x;
    die();
}

?>

<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)
      { 
     document.getElementById('output').innerHTML += xmlHttp.responseText + "<br />";     
      }
    }   
    xmlHttp.open("GET","ajax-test.php?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">
<div id='output'></div>
</body>

</html>

The PHP part (at the top) basically is just to waste some time, depending on the SECONDS value. Though, it really only takes about 1/6th the amount of time requested. Here is the output from running the script:

5: x=707.106074079
10: x=999.9995
30: x=1732.05051889

Basically, this is just showing that 5 DELAY(5) is returning before DELAY(10) which is returning before DELAY(30), even though they are being requested in the opposite order.

So, take a look at your asp delay code, as the problem must be there. Sorry I can't help much otherwise.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜