日期:2014-05-17  浏览次数:21240 次

为什么ajax在chorme浏览器中得不到数据?
源代码如下:(保存为html文件,用在chorme浏览器打开,放在本地,放在远程都没有获取数据的反应。IE下没有问题。)


<html>

<head>

<script type="text/javascript">

function loadXMLDoc()

{

var xmlhttp;

if (window.XMLHttpRequest)

  {// code for IE7+, Firefox, Chrome, Opera, Safari

  xmlhttp=new XMLHttpRequest();

  }

else

  {// code for IE6, IE5

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  }

xmlhttp.onreadystatechange=function()

  {

  if (xmlhttp.readyState==4 && xmlhttp.status==200)

  {

  document.getElementById("myDiv").innerHTML=xmlhttp.responseText;

  }

  }

xmlhttp.open("GET","http://www.w3school.com.cn/ajax/demo_post2.asp?t=" + Math.random(),true);

xmlhttp.send();

}

</script>

</head>

<body>



<h2>AJAX</h2>

<button type="button" onclick="loadXMLDoc()">请求数据</button>

<div id="myDiv"></div>



</body>

</html>


------解决方案--------------------
你的远程服务器是http://www.w3school.com.cn吗?
------解决方案--------------------
http://zhidao.baidu.com/question/382446089.html