2015-12-01 104 views
-4

有誰知道如何處理這些錯誤?我是Javascript新手,目前我正在嘗試學習esri的一些API。我真的不明白這些錯誤意味着什麼或如何去解決它們。這裏是錯誤:有沒有人真的知道如何解決這些錯誤?

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> 

任何幫助將是偉大的。我不得不說,我完全失去了這一點。

+1

不要在文件協議上運行。瞭解CORS – epascarello

+0

@Steve瀏覽器鉻/鉻? – guest271314

+0

是的它是鉻 – Steve

回答

6

看的網址:

file://www.arcgis.com/..... 

AJAX不會在文件系統上運行。 (無論如何,這可能不是一個有效的文件系統路徑,它看起來像應該是是一個網站。)它適用於Web服務器。

想必您直接從您的文件系統打開此HTML文件。相反,將其託管在Web服務器(可以是您的本地計算機)上並通過HTTP打開它。

您的AJAX請求可能還有其他問題。也許你沒有正確地指定URL(這裏沒有一個足夠完整的例子可以肯定),或者甚至一旦你向Web服務器發出請求,它可能是一個跨域請求。我們不能真正知道。但至少,這必須在Web服務器上運行。

+0

_「AJAX不適用於文件系統。」_?問題處的URL不顯示有效,但ajax可以在'file:'協議中使用 – guest271314

+0

如何知道何時使用服務器以及何時使用文件?當我從文件運行它時,類似的一段代碼執行時沒有錯誤。 – Steve

相關問題