Javascript 有人知道如何修复这些错误吗?
有人知道如何处理这些错误吗?我是Javascript新手,目前正在尝试学习esri的一些api知识。老实说,我不明白这些错误是什么意思,也不知道如何去纠正它们。以下是错误:Javascript 有人知道如何修复这些错误吗?,javascript,Javascript,有人知道如何处理这些错误吗?我是Javascript新手,目前正在尝试学习esri的一些api知识。老实说,我不明白这些错误是什么意思,也不知道如何去纠正它们。以下是错误: XMLHttpRequest cannot load file://www.arcgis.com/sharing/rest/content/items/b3c3566f3e1c4b6b8035185fba217f54?f=json. Cross origin requests are only supported for p
XMLHttpRequest cannot load file://www.arcgis.com/sharing/rest/content/items/b3c3566f3e1c4b6b8035185fba217f54?f=json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
q {message: "Unable to load file://www.arcgis.com/sharing/rest/…b3c3566f3e1c4b6b8035185fba217f54?f=json status: 0", response: Object, status: 0, responseText: "", xhr: XMLHttpRequest…}
下面是制作它们的代码
<!doctype html>
<html>
<head>
<title>Create a Web Map</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.14/esri/css/esri.css">
<style>
html, body, #mapDiv, .map.container{
padding: 0;
margin: 0;
height: 100%;
}
</style>
<script>var dojoConfig = { parseOnLoad:true };</script>
<!--<script> Access-Control-Allow-Origin: null </script> perhaps this could be part of a solution-->
<script src="http://js.arcgis.com/3.14compact/"></script>
<script>
var map;
require([
"esri/map",
"esri/arcgis/utils",
"dojo/domReady!"
], function(Map, arcgisUtils){
arcgisUtils.createMap( "b3c3566f3e1c4b6b8035185fba217f54", "mapDiv").then(function (response) {
map = response.map;
});
});
</script>
</head>
<body>
<div id="mapDiv"></div>
</body>
</html>
创建网络地图
html,body,#mapDiv,.map.container{
填充:0;
保证金:0;
身高:100%;
}
var dojoConfig={parseOnLoad:true};
var映射;
要求([
“esri/map”,
“esri/arcgis/utils”,
“dojo/domReady!”
],函数(映射、arcgisUtils){
createMap(“b3c3566f3e1c4b6b8035185fba217f54”,“mapDiv”)。然后(函数(响应){
map=response.map;
});
});
任何帮助都会很好。我不得不说,我现在完全迷路了。看看网址:
file://www.arcgis.com/.....
AJAX在文件系统上不起作用。(无论如何,这也不可能是一个有效的文件系统路径,它看起来应该是一个网站。)它在web服务器上工作
假设您是直接从文件系统打开此HTML文件。相反,将其托管在web服务器(可以是您的本地计算机)上,并通过HTTP打开它
关于AJAX请求,可能还有其他问题。也许您没有正确地指定URL(这里没有足够完整的示例可以确定),或者甚至在向web服务器发出请求时,也可能是跨域请求。我们真的不知道。但至少,这必须在web服务器上运行。不要在文件协议上运行。了解CORS@Steve浏览器是chrome/chrome吗?“AJAX在文件系统上不工作。”?问题中的url似乎无效,但ajax可用于
文件:
协议如何知道何时使用服务器和何时使用文件?当我从一个文件运行它时,一段类似的代码没有错误地执行。