<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
var xmlhttp;
function loadXMLDoc(url)
{
xmlhttp=null;
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
xmlhttp=new ActiveObject("Microsoft.XMLHTTP");
}
if(xmlhttp!=null)
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else{
alert("your browser does not support XMLhttp.");
}
}
function state_Change(){
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
document.getElementById('T1').innerHTML=xmlhttp.responseText;
}
else{
alert("Problem retrievinf data:"+xmlhttp.statusText);
}
}
}
</script>
</head>
<body onload="loadXMLDoc('a.txt')">
<div id="T1" style="border:1px; solid black;height:40px;width:300;padding:5;"></div><br/>
<button onclick="loadXMLDoc('b.txt')">click</button>
</body>
</html>
同源策略例子
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.