日期:2014-05-16  浏览次数:20551 次

ajax对浏览问题 急求解决 谢谢
HTML code
<script type="text/javascript">
      var xMLHttpRequest = null;
      //开始一个请求
      function doWord(){
          var strUrl="http://127.0.0.1:8080/dominoTest/wordTest.do?xmbh=";
          var  strXmbh = document.formtx.strXmbh.value;
          if(strXmbh != "" && strXmbh != null){
              doAjax(strUrl+strXmbh);
          }else{
              window.alert("项目编号不能为空");
          }
      }
      
      //创建Ajax
    function doAjax(strUrl){
        createXMLHttpRequest();
        xMLHttpRequest.onreadystatechange = returnFunction;
        xMLHttpRequest.open("GET",strUrl,true);//false为同步调用,true为异步调用
        xMLHttpRequest.setRequestHeader( "connectionTimeout" , "100000" ) ; //代理运行超过100秒,则自动断开请求,释放HTTP资源
        xMLHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); 
        xMLHttpRequest.send(null);
    }
    
    //创建request对象
    function createXMLHttpRequest(){
        if(window.XMLHttpRequest){
            xMLHttpRequest = new XMLHttpRequest();
        }else if(window.ActiveXObject){
            try{
                xMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(e){
                window.alert(e+"创建XMLHttpRequest对象失败");
            }
        }
        
        if(!xMLHttpRequest){
            window.alert("XMLHttpRequest对象创建失败");
        }
    }
    //回调函数
    function returnFunction(){
        if(xMLHttpRequest.readyState == 4){//描述一种"已加载"状态;此时,响应已经被完全接收
            if(xMLHttpRequest.status == 200){
                var httpResponse = xMLHttpRequest.responseText;
                if(httpResponse == "1"){
                    window.alert("数据库连接失败");
                }else if(httpResponse == '2'){
                    window.alert("合同生成失败");
                }else{
                    window.alert("合同生成成功");
                }
            }else{
                document.write("未找到您输入的地址或服务器505错误");   
            }
        }
    }
  </script>



这个是我ajax的代码,中午还好着里,晚上拿出来改改,可是还刚部署上,就跑不起来,在IE上一直报没有权限,在其他浏览器一直报那个document.write("未找到您输入的地址或服务器505错误") 信息,请问,怎么回事了?是不是我哪儿弄错了,可是我研究了半天也没看出来哪儿有问题啊 。请大家帮我看一下,谢谢。浏览兼容也有问题。

------解决方案--------------------
localhost!==127.0.0.1,你的地址已经写死了成127.0.0.1了,所以你访问网站一定要127.0.0.1

你写绝对路径就好了,干嘛要加127.0.0.1?

JScript code
 var strUrl="/dominoTest/wordTest.do?xmbh=";