!-- 文件名: 16_3.htm --
html
head
meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" /
title加载一个文本文件到一个HTML元素中/title
script type=\"text/javascript\"
var xmlhttp;
// 声明一个变量
function loadXMLDoc(url)
// 函数:载入文档
{
xmlhttp=null;
if (window.XMLHttpRequest)
// 如果存在XMLHttpRequest对象
{// code for Firefox, Opera, IE7, etc.
xmlhttp=new XMLHttpRequest();
alert(\"haha\");// 创建一个新的XMLHttpRequest对象
}
else if (window.ActiveXObject)
// 如果存在ActiveXObject对象
{// code for IE6, IE5
xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");
alert(\"hehe\");// 创建一个新的ActiveXObject对象
}
if (xmlhttp!=null)
// 如果xmlhttp不为空
{
xmlhttp.onreadystatechange=state_Change;
alert(\"1\");// 设置状态
xmlhttp.open(\"GET\",url,true);
alert(\"2\"); // 打开
xmlhttp.send(null);
alert(\"3\");// 发送
}
else
{
alert(\"Your browser does not support XMLHTTP.\");
}
}
function state_Change()
// 函数:状态改变时候调用的函数
{
if (xmlhttp.readyState==4)
// 载入完毕
{// 4 = \"loaded\"
alert(\"4\");
if (xmlhttp.status==200)
// 完成
{// 200 = \"OK\"
alert(\"200\");
document.getElementById(\'T1\').innerHTML=xmlhttp.responseText;
}
else
{
alert(\"Problem retrieving data:\" xmlhttp.statusText);
}
}
else alert(\"201\");
}
/script
/head
body onLoad=\"loadXMLDoc(\'test_xmlhttp.txt\')\"
center
h1加载一个文本文件到一个HTML元素中/h1
hr
br
h5单击如下按钮.../h5
div id=\"T1\" style=\"border:1px solid black;height:40;width:300;padding:5\"/div
br /
button onClick=\"loadXMLDoc(\'test_xmlhttp2.txt\')\"载入文本/button
/center
/body
/html
它只输出“haha\" 跟 \"1\"就没了。按输入文本没反应。
|