I use the same code for dojo.request
as in a previous project, except for the URL address and the fact I'm calling service's iteminfo
instead of layer's addFeatures
. However, I always get the following error:
Unable to load http://foobar.com/arcgis/rest/services/MapServer/info/iteminfo status: 0
I confirmed this in Firefox and IE. The status shown by Firebug or Visual Studio is always 0, even though the status shown in Fiddler is 200. It shows 0 also when I mess something up and get 401 in Fiddler.
So, here's my code:
var promise = require('dojo/request').post(uri, {
handleAs: "json",
query: "f=pjson",
headers: {
"X-Requested-With": null
},
//timeout: 60000, //commenting this in and out changes nothing
withCredentials: true
});
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
}
);
I want the output as a JSON, so I added the query
option; without it, Fiddler shows the output as HTML instead. I found an answer indicating that the response may need time, but either it's not my case or something more complex than simple timeout
option is needed.
All my test variables (res
,rej
...) hold false
. So the request seems unresolved, unfulfilled etc. in the code, but Fiddler returns the response - I'm not skilled enough in these network arts to be able to draw conclusion from this, so I ask the question.
Also, I have a vague impression that some additional headers should be the solution. I've tried adding accept
(nothing changed) and content-type
(it went pre-flight and Fiddler reported status 401).
EDIT: the response header contains following security info:
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Origin: http://localhost:30322 //origin for now
Access-Control-Allow-Origin: *