使用AJAX时Chrome中出现错误
好的,我一直在Ajax中工作,当我在IE中运行它时,它工作得很好 这是HTML代码:使用AJAX时Chrome中出现错误,ajax,google-chrome,Ajax,Google Chrome,好的,我一直在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 loadXMLD
<!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>
我尝试使用–允许从文件访问文件,但它不起作用,或者可能我使用了错误的
还有人可以解释为什么会发生此错误?您应该在dropbox设置中检查该目录文件的访问权限。我看到您已经将JQuery包含到页面中。只用
$('#myDiv').load("https://www.dropbox.com/s/tq4qhxqtqpgjd57/ajax_info.txt");
使用JQuery可以让您忽略浏览器兼容性问题,并使您的代码更具可读性。查看此答案我真的不明白answeri Check在公用文件夹中,并且在IEi中运行顺利。我在浏览器中运行此命令:不显示任何内容将替换整个函数体。从
函数loadXMLDoc(){
到}
。
$('#myDiv').load("https://www.dropbox.com/s/tq4qhxqtqpgjd57/ajax_info.txt");