<script type="text/javascript">
//AJAX 函数(fun为空则同步否异步)
function sendRequest(met,url,fun)
{
if(window.ActiveXObject)
{
xmlHttp
=new ActiveXObject('Microsoft.XMLHTTP');
}
else
{
xmlHttp
=new XMLHttpRequest();
}
if(fun)
{
xmlHttp.open(met,url,
true);
xmlHttp.onreadystatechange
=fun;
xmlHttp.send(
null);
}
else
{
xmlHttp.open(met,url,
false);
xmlHttp.send(
null);
}
}
//测试函数
function Test()
{
//同步执行
sendRequest('GET','server.php');
ExecTest();
//异步执行
sendRequest('GET','server.php',ExecTest);
}
function ExecTest()
{
if(xmlHttp.readyState==4&&xmlHttp.status==200)
{
var result=xmlHttp.responseText;
alert(result);
}
}
</script>

相关文章:

  • 2021-12-20
  • 2021-09-07
  • 2021-09-12
  • 2021-12-10
  • 2021-11-04
  • 2021-12-20
  • 2021-09-21
  • 2021-08-12
猜你喜欢
  • 2021-06-28
  • 2021-12-08
  • 2022-02-09
  • 2022-12-23
  • 2021-12-10
  • 2021-11-04
  • 2021-11-04
相关资源
相似解决方案