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

js xmlhttp 请求网页为什么不支持谷歌浏览器!
为什么这段代码,只支持IE,谷歌浏览器为什么打不开呢?求指导啊!
<html>
<head>
<script type="text/javascript">
var xmlhttp;
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for IE7, Firefox, Opera, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("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)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"
    document.getElementById('A1').innerHTML=xmlhttp.status;
    document.getElementById('A2').innerHTML=xmlhttp.statusText;
    document.getElementById('A3').innerHTML=xmlhttp.responseText;
    }
  else
    {
    alert("Problem retrieving XML data:" + xmlhttp.statusText);
    }
  }
}
</script>
</head>



<body>
<h2>Using the HttpRequest Object</h2>

<p><b>Status:</b>
<span id="A1"></span>
</p>

<p><b>Status text:</b>
<span id="A2"></span>
</p>

<p><b>Response:</b>
<br /><span id="A3"></span>
</p>

<button onclick="loadXMLDoc('http://www.baidu.com')">Get XML</button>

</body>
</html>
xmlhttprequest javascript

------解决方案--------------------
跨域的问题,好像现在的IE也不能跨域
------解决方案--------------------
引用:
Quote: 引用:

跨域的问题,好像现在的IE也不能跨域
那你晓得怎么解决这问题不?IE貌似是可以的!

可以通过后台去取,再输出
------解决方案--------------------
跨域了,ie本地file测试安全配置是启用了通过域访问数据源,所以能跨域请求,其他浏览器不会将返回的数据交给js,status为0

IE你搭建服务器来访问就报错了,默认internet安全区域是通过域访问数据源是禁用的
------解决方案--------------------
引用:
Quote: 引用:

Quote: 引用:

跨域的问题,好像现在的IE也不能跨域
那你晓得怎么解决这问题不?IE貌似是可以的!

可以通过后台去取,再输出

比如p