Javascript 如何同时调用三个ajax函数?

Javascript 如何同时调用三个ajax函数?,javascript,asp-classic,Javascript,Asp Classic,下面是我的asp页面中的代码 Ajax.asp 在Delay_Page.asp中,这是代码 <% 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

下面是我的asp页面中的代码

Ajax.asp

在Delay_Page.asp中,这是代码

<%
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"
%>
上面的代码运行良好,但我想解决一些问题

我需要的是

我想一起调用Delay'30'&&Delay'10'&&Delay'5'函数

现在的条件是,当第一个函数完成延迟'30'后,它进入第二个函数

现在完成该功能的总时间为45秒30+10+5

我需要在30秒内完成这三个功能


希望你的帮助,我真的看不出你的问题在哪里,所以它一定在你的asp页面上。很抱歉,我现在没有办法测试asp,所以我也帮不上忙。但是,我用PHP编写了一个假延迟,并运行了您的javascript。以下是我用来测试的内容:

<?
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>
基本上,这只是表明5 DELAY5在DELAY10之前返回,而DELAY10在DELAY30之前返回,即使请求顺序相反


所以,看看你的asp延迟代码,因为问题一定在那里。很抱歉,否则我帮不了什么忙。

谢谢。。。我需要的是,我想输入Delay'30'和Delay'10'和Delay'5'这些功能parallel@Alex:您正在并行运行请求,但可能存在浏览器限制。有些浏览器将每个主机的连接数限制为两个。您应该研究类似jQuery的东西来处理ajax调用。。。使用ActiveX对象进行try/catch只涉及IE浏览器,jQuery实现可以在所有主要平台上工作,而不需要任何真正复杂的代码。
<?
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>
5: x=707.106074079
10: x=999.9995
30: x=1732.05051889