<script>
window.onload=function(){
var oBtn=document.getElementById('btn1');
oBtn.onclick=function(){
var oAjax=new XMLHttpRequest();
oAjax.open('GET','a.txt',true);
oAjax.send();
oAjax.onreadystatechange=function(){
if(oAjax.readyState==4){ 
if(oAjax.status==200)
{
alert('成功');
}
else{
alert('失败');
}
}   
};
};
};
</script>
这是页面的JS,页面有一个读取按钮。然后用IIS7.5,把这个页面和a.txt都放到了C:\inetpub\wwwroot里面。a.txt里面有字符,就abc。但是怎么运行后点击页面的读取,是弹出失败呢?不知道问题出了哪了。。请教各位~!

解决方案 »

  1.   

    oAjax.send(); 放到后面试试<script>
    window.onload=function(){
        var oBtn=document.getElementById('btn1');
        oBtn.onclick=function(){
                var oAjax=new XMLHttpRequest();    
                oAjax.open('GET','a.txt',true);
                
                oAjax.onreadystatechange=function(){
                    if(oAjax.readyState==4){ 
                        if(oAjax.status==200)
                        {
                            alert('成功');
                            }
                            else{
                                alert('失败');
                                }
                        }   
                    }; 
                    oAjax.send();
            };
        };
    </script>
      

  2.   

    LZ试试把oAjax.open('GET','a.txt',true);里a.txt换成URL的形式?