javascript:Ajax XMLHttpRequest-文件未加载到Chrome和IE8上

javascript:Ajax XMLHttpRequest-文件未加载到Chrome和IE8上,javascript,ajax,google-chrome,internet-explorer-8,Javascript,Ajax,Google Chrome,Internet Explorer 8,关于这个错误[在图片中],我上网并应用了所有的技术,例如,它仍然不能在我的本地工作。我只是想从系统本地[D:/somefolder]获取JSON文件。有什么帮助吗?请 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="application/json; charset=UTF-8"/> </head> <body> <div i

关于这个错误[在图片中],我上网并应用了所有的技术,例如,它仍然不能在我的本地工作。我只是想从系统本地[D:/somefolder]获取JSON文件。有什么帮助吗?请

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="application/json; charset=UTF-8"/>
</head>
<body>
<div id="serverReply"><b><a href="#"  onclick="getMessage();">Get message</a></b></div>
<script type="text/javascript">
function getMessage()
{
  if (window.XMLHttpRequest)
  {

      xmlhttp=new XMLHttpRequest();

  }else
  {

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

    xmlhttp.onreadystatechange=function()
  {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {

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

    }
  }
    xmlhttp.open("GET","carousel-data.json",true);
    xmlhttp.send();
}
</script>
</body>
</html>

函数getMessage()
{
if(window.XMLHttpRequest)
{
xmlhttp=新的XMLHttpRequest();
}否则
{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“serverReply”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”,“carousel data.json”,true);
xmlhttp.send();
}

我希望您使用的是一些服务器。很抱歉,我没有使用任何服务器,我只需要在文件中使用此文件://,我的本地系统中只有json文件。还有。。。。他没有,错误清楚地显示了一个文件协议,并且如前所述,ajax不能在不同的协议、端口等上工作。请使用服务器。但是,相同的代码在Firefox上工作得非常好。