1.这是我的js代码,没有用jq。
window.onload =function(){ document.getElementById('mya').onclick = function(){ var request = new XMLHttpRequest(); request.open('GET','hello.txt'); request.send(null); request.onreadystatechange = function(){ if (request.readyState == 4) { if (request.status == 200) { alert(request.responseText); } } } return false; } }2.这是我的html代码
点我
请问,在不搭建服务器的情况下,如何获取本地的数据?先谢谢了!
window.onload=function(){
var btn=document.getElementById('mya');
btn.onclick=function(){
//jianrongpanduan
if(window.XHLHttpRequset){
var oAjax=new XMLHttpRequset();
}
else{
var oAjax=new ActiveXObject()
}
oAjax.open('GET','hello.txt',true);
oAjax.send();
oAjax.onreadystatechange=fuction(){
if(oAjax.readyState==4){
if(oAjax.ststus==200){
alert(oAjax.responseText);
}
}
}
}
}
没有搭建服务器,通过http协议访问时,要使用Firefox来测试,其他ie(除非你用的acx创建,看你代码想判断的XMLHttpRequest,IE7+支持,使用此对象会报跨域错误)或者chrome不允许访问本地文件