【发布时间】:2013-06-10 06:45:09
【问题描述】:
好的,我一直在使用 Ajax,当我在 IE 中运行它时,它运行良好 这是 HTML 代码:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
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","https://www.dropbox.com/s/tq4qhxqtqpgjd57/ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
问题是当我在 Chrome 中运行它时,它得到了这个错误:
XMLHttpRequest cannot load https://www.dropbox.com/s/tq4qhxqtqpgjd57/ajax_info.txt. Origin file:// is not allowed by Access-Control-Allow-Origin.
我尝试使用 –allow-file-access-from-files 但它不起作用或者我用错了
也有人可以解释一下为什么会出现这个错误?
【问题讨论】:
-
我不太明白那个答案
标签: ajax google-chrome