如果嘗試連接到樣本休息服務時出現以下錯誤,請提供Arcgis Javascript API docs。如何使用dojo/store/JsonRest工作ArcGIS Rest服務
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://bcgphp' is therefore not allowed access.
繼dojo docs我已經設置了我的dojo/store,如下所示。
var jsonStore = new JsonRest({
target: "//sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/"
});
jsonStore.get(5);
我還試圖使在某些報頭每道場docs,其返回的相同的錯誤與上述代碼。
var jsonStore = new JsonRest({
target: "//sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/",
headers: {'X-Requested-With': 'XMLHttpRequest'}
});
jsonStore.get(5);
當我使用ArcGIS Javascript來查詢我能夠做出與本demo提供了以下代碼這個請求,這不會導致任何跨域的問題。
var queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5");
var query = new Query();
query.returnGeometry = false;
query.outFields = [
"SQMI", "STATE_NAME", "STATE_FIPS", "SUB_REGION", "STATE_ABBR",
"POP2000", "POP2007", "POP00_SQMI", "POP07_SQMI", "HOUSEHOLDS",
"MALES", "FEMALES", "WHITE", "BLACK", "AMERI_ES", "ASIAN", "OTHER",
"HISPANIC", "AGE_UNDER5", "AGE_5_17", "AGE_18_21", "AGE_22_29",
"AGE_30_39", "AGE_40_49", "AGE_50_64", "AGE_65_UP"
];
queryTask.execute(query, showResults);
function showResults (results) {
console.log(results);
}
我真的想如果可能的話用dojo.store,這樣我就可以構建使用道場
好的,我有點想這是問題所在。相反,我開始走下道場/商店/記憶之路。 – marty