myRequest.open中值true的含义(“GET”,url,true)?

时间:2018-05-07 11:11:17

标签: html xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Example</title>
<script type="text/javascript">
var myRequest = new XMLHttpRequest();
function loadXMLDoc(url)
{
myRequest.onreadystatechange = onResponse;
myRequest.open("GET", url, true);
myRequest.send();
}
function onResponse()
{
if(myRequest.readyState == 4 && myRequest.status == 200)
document.getElementById("A").innerHTML = myRequest.responseXML.documentElement.getElementsByTagName("color")[1].childNodes[0].nodeValue;
}
</script>
</head>
<body>
<p>Response: <span id="A"></span></p>
<button onclick="loadXMLDoc('example.xml')">Get Color</button>
</body>
</html>

在myRequest.open中显示值true(“GET”,url,true)。

湾myRequest.readyState字段存在什么值,它们是什么意思?

℃。单击“获取颜色”按钮后,将更新example.htm代码的哪一部分?

d。如果要访问的XML文件以获取颜色数据,则具有以下代码:

<color_list>
<color>Red</color>
<color>Green</color>
<color>Blue</color>
</color_list>

在按下“获取颜色”按钮并更新页面后,绘制example.htm页面的Web浏览器页面显示。

0 个答案:

没有答案