I have been attempting to enhance an ArcGIS feature service using the Arcgis JavaScript API and dojo/request
. I have followed guidance on how to include the request module, as indicated in this link. While I am able to receive a response from the server, I have struggled to successfully execute the callback function despite trying various solutions for several days. Here is my code:
esri.config.defaults.io.corsEnabledServers.push("remotearcgisserver.com");
var uri = "http:/remotearcgisserver.com/arcgis/rest/services/foo/bar/FeatureServer/0/addFeatures"
//no error here, so I suppose the dojo/request is requested correctly
var promise = require('dojo/request').post(uri, {
data: "features=" + _json + "&rollbackOnFailure=true&f=pjson", handleAs: "json", timeout: 2000,
headers: {
"X-Requested-With": null
}
});
var res = promise.isResolved();
var rej = promise.isRejected();
var ful = promise.isFulfilled();
var can = promise.isCanceled();
var respres = promise.response.isResolved();
var resprej = promise.response.isRejected();
var respful = promise.response.isFulfilled();
var respcan = promise.response.isCanceled();
promise.response.then(
//success
function (response) {
//something
},
//fail
function (error) {
//something different
}
);
All the test variables return 'false' (not resolved, not rejected, not fulfilled, and not canceled). Even though the service does not require a password and has set X-Frame-Options: SAMEORIGIN
, Access-Control-Allow-Origin: *
should override it (it was initially rejected before setting
Access-Control-Allow-Origin</code). However, none of the success/fail functions are being executed.</p>
<p>I also attempted to use <code>dojo/request/iframe
and dojo/request/xhr
, but to no avail. The issue seems to possibly be related to how I am utilizing the require statement due to my limited understanding of dojo
.
UPDATE: The problem appears to be with my IIS server, which does not trust our arcgis server. Further tests indicate that the response is indeed being rejected. Although I initially believed that
esri.config.defaults.io.corsEnabledServers.push
would resolve this, it seems more complex or perhaps I am incorrectly implementing it.
UPDATE2: It turns out that
esri.config.defaults.io.corsEnabledServers.push
was a leftover from my previous attempts to work around issues with esri/request
. Progress has been made by adding "X-Requested-With": null
to the headers. While the response is now accepted, I am still unable to successfully trigger the callback function.