Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AJAX新手,需要澄清一下_Ajax - Fatal编程技术网

AJAX新手,需要澄清一下

AJAX新手,需要澄清一下,ajax,Ajax,我曾经从事过像COBOL这样的结构化编程,现在正试图学习AJAX 我在W3学校看到这段代码,有以下问题吗 问题: 1.xmlhttp.onreadystatechange=function()如何计算此函数。在计算返回之前,是否需要执行xmlhttp.open()和xmlhttp.send() <html> <head> <script type="text/javascript"> function loadXMLDoc() { var xmlhttp; i

我曾经从事过像COBOL这样的结构化编程,现在正试图学习AJAX

我在W3学校看到这段代码,有以下问题吗

问题: 1.xmlhttp.onreadystatechange=function()如何计算此函数。在计算返回之前,是否需要执行xmlhttp.open()和xmlhttp.send()

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>

函数loadXMLDoc()
{
var-xmlhttp;
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“myDiv”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”,“ajax_info.txt”,true);
xmlhttp.send();
}
让AJAX更改此文本
更改内容
AJAX是异步的

调用
send()
后,浏览器将在后台发送请求


当服务器回复时,浏览器将调用您的
onreadystatechange
处理程序;这发生在您的其余代码运行后的某个时间。

我强烈建议您使用jQuery,即使您不熟悉它,至少它可以轻松地使用。因此,当服务器响应延迟时,它会等待响应发送吗?@user1050619:No;没有什么会等待。它只是在以后才会调用回调。