如何调用3 AJAX功能整合在一起? [英] How to invoke three ajax functions together?
问题描述
下面是code在我的ASP页
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>
在 Delay_Page.asp 这是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"
%>
以上code工作正常,但有些问题我想解决
The above code is working fine, but some problems i wants to solve
我需要的是
我要调用延迟('30')及和放大器;延迟('10')及与放大器;延迟('5'))
功能结合在一起
i want to invoke Delay('30')&& Delay('10')&& Delay('5'))
functions together
现在的情况是,当第一功能完成延迟('30')
然后后才它进入第二个功能
Now the condition is, when the first function finish Delay('30')
then after only it goes to the second function
现在总时间来完成功能为45秒(30 + 10 + 5)
Now Total time to finish the function is 45 seconds (30 + 10 + 5)
我需要在30秒内完成这三个功能
I need to finish these three functions in 30 seconds
希望你的帮助PLZ,
推荐答案
我真的不能看到你的问题,所以必须在你的ASP页。我很抱歉地说,我不能在目前的测试ASP的方式,所以我不能帮助那里。但是,我写在PHP假延迟和运行的JavaScript。下面是我用来测试:
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>
PHP的一部分(在顶部)基本上只是浪费了一些时间,这取决于秒值。虽然,它真的只需要大约1/6的要求时间量。下面是运行该脚本的输出:
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
基本上,这只是显示,5 DELAY(5)这是DELAY(30)前返回,即使被要求它们以相反的顺序DELAY(10)之前回来了。
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.
那么,来看看你的ASP延迟code,因为这个问题必须在那里。对不起,我不禁大为不然。
So, take a look at your asp delay code, as the problem must be there. Sorry I can't help much otherwise.
这篇关于如何调用3 AJAX功能整合在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!