Dojo.request.post - returned promise says “rejected”, but server seems to have accepted the request

杀马特。学长 韩版系。学妹 提交于 2019-12-11 20:23:23

问题


I try to add a feature to an ArcGIS feature service through Arcgis JavaScript API and dojo/request. I've already been pointed to how to include the request module and I get some response from the server, but after few days of exploring different solutions I didn't manage to execute the callback function. 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 hold 'false' (not resolved, not rejected, not fulfilled and not canceled). The service has no password and even though it has X-Frame-Options: SAMEORIGIN, Access-Control-Allow-Origin: * should override it (before we have set Access-Control-Allow-Origin, it was rejected). Still, none of the success/fail functions gets executed.

I've tried dojo/request/iframe and dojo/request/xhr as well, but nothing changed. I didn't change anything but the require statement.

What should I do to get and process the response? I'm new to dojo, so I expect I misunderstood something basic.

EDIT: the problem is on my IIS server, which doesn't trust our arcgis server. The new test variables shown that the response is being rejected. I thought esri.config.defaults.io.corsEnabledServers.push should handle this, but either I use it wrong or it's more complicated.

EDIT2: esri.config.defaults.io.corsEnabledServers.push was an artifact from times when I tried to workaround some problems through esri/request. I managed to make another step by adding "X-Requested-With": null to headers. The response is no longer rejected, but I still can't execute the the callback function.


回答1:


Solved! I solved the problems that I was asking for in the edits. The problem that remained was with the uri generation - I made it dynamically through Orchard's ViewBag, and I didn't notice it's wrong until I changed the address to another service. Now I use a static URI and everything works right.



来源:https://stackoverflow.com/questions/33781280/dojo-request-post-returned-promise-says-rejected-but-server-seems-to-have-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!