同源策略例子

来源:互联网 发布:淘宝自媒体是什么 编辑:程序博客网 时间:2024/06/18 17:04
<!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>
0 0
原创粉丝点击