I am receiving the following error when attempting to connect to a sample rest service provided the the Arcgis Javascript API docs.
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://bcgphp' is therefore not allowed access.
Following the dojo docs I have setup my dojo/store as follows.
var jsonStore = new JsonRest({
target: "//sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/"
});
jsonStore.get(5);
I have also tried passing in some headers per the dojo docs, which returned the same error as the code above.
var jsonStore = new JsonRest({
target: "//sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/",
headers: {'X-Requested-With': 'XMLHttpRequest'}
});
jsonStore.get(5);
When I use the Arcgis Javascript to Query I am able to make this request with the following code provided in this demo This does not cause any cross domain issues.
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);
}
I would really like to use the dojo.store if possible so that I can structure my app using the MVC technique provided by Dojo
dojo/store/JsonRest
expects the server to adhere to a specific protocol, but ArcGIS services have their own specification. See the Implementing a REST Server section of the JsonRest docs. So regardless of any CORS issues, I don't think is possible to point dojo/store/JsonRest
at an ArcGIS Online service w/o wrapping it in some RESTful service that adheres to the protocol the JsonRest store expects.
Depending on the number of records in your service and how often you will need to write back to the server, you might try pulling all the records you need into a dojo/store/Memory
store using the QueryTask
when the page loads. I've worked on a project where we successfully used that technique.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With