Upon sending a post request with Dojo.request.post, the returned promise indicates "rejected", despite the server successfully processing the request

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.

Answer №1

Issue Resolved! After making changes to the address of a service, I discovered that the problem lied in the dynamic URI generation using Orchard's ViewBag. By switching to a static URI, all issues were resolved successfully.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the reason behind the necessity of having event triggers created within the AJAX request?

What's the reason behind this functioning: $.ajax( { url: "/some/url.php", data: { s:"stuff" }, success: function(result) { // Result is <button id="clickme">Click me!</button> $("#container").html(result); ...

"Utilizing the Image onLoad event in isomorphic/universal React: Activating event registration once the image has been

When a page is rendered isomorphically, the image can be downloaded before the main script.js file. This means that the image may already be loaded before the react register's the onLoad event, resulting in the event never being triggered. script.js ...

Please log out of the session if the selected item is unavailable

Can someone help me figure out if what I'm attempting in asp.net is feasible? I'm encountering an issue that I could use some expertise on. :) Within my HTML view, I am fetching values from the session and assigning them to select list items. H ...

Issues with the onChange function in a Material UI TextField component (React)

I'm currently working on a form using Material UI in React to send data to MongoDB. My form includes DatePickers, Select, and TextField components, all from Material UI. Here's the code snippet for handling state changes: const [project, setProje ...

Choose a node from descendants based on its attribute

I am working with an interface that switches between displaying different div elements. Each div element has their children arranged differently, and when the switch happens, I need to access a specific child node of the newly displayed div. However, I fin ...

Automatically integrating Nivo Lightbox into your website

I incorporated Nivo Lightbox into my website, seamlessly integrating all images with the plugin using the following code: <div class="portfolio-item"> <div class="portfolio-thumb "> <a class="lightbox" data-lightbox-type="ajax" title="Strat ...

Ag-grid: how to reset a cell when using the "agSelectCellEditor"

According to the documentation on ag-grid: If Backspace or Delete is pressed, the default editor will clear the contents of the cell. However, this behavior does not apply when using the "agSelectCellEditor." Pressing Delete or Backspace puts the cell i ...

Avoiding type errors in d3 v5 axis by using Typescript

I am new to TypeScript and I have some code that is functioning perfectly. I believe if I define a type somewhere, d3's generics will come into play? Within my code, I have an xAxis and a yAxis. Both are the same, but D3 seems to have an issue with t ...

Error: The function RFB is not defined

Trying to set up a VNC client using AngularJS (tutorial link here), but encountering an error while running the application: TypeError: RFB is not a function Below is the server.js code snippet: var RFB = require('rfb2'), io = require(&apos ...

Sharing information across various web pages

Struggling with PHP as a beginner. Currently using HTML5, CSS3, jQuery, and Bootstrap 4. I have 4 HTML pages on my site. The first page displays 4 squares labeled A, B, C, and D. Users select one square and click "Next" to proceed to page 2. Page 2 must ...

I am leveraging AngularJS to display a modal window with Bootstrap and Spring servlet integration

In my project, I am utilizing AngularJS to display multiple pages. One of these pages contains a smart-table where I showcase the details of "users". When I wish to edit one of the users, I aim to display the edit page as a popup window. Below is an excer ...

What is the method for adding data to a table without utilizing an ID field?

Here is the code I have written: This table contains details of the candidates: <table id="candidates-table" class="table table-striped table-bordered"> <thead class="thead-dark"> <tr> <th scope="col">Candidate Picture ...

It seems that Firefox is ignoring the word-wrap style when the class of a child element is changed

Take a look at this: var iconIndex = 0; var icons = ['check', 'chain-broken', 'flag-o', 'ban', 'bell-o']; $('button:eq(0)').click(function() { iconIndex = (iconIndex + 1) % icons ...

How can one effectively compare the value received from value.val() with a regular expression in search fields? Is it possible to use multiple

Feeling a bit overwhelmed. I have come up with this code that is working really well: HTML: <p class="no-result"> Nothing found. </p> JS: (JQuery) $("#itemSearch").on("keyup", function () { if ($("#itemSearch").val() == '') { ...

I'm looking to utilize this script to generate multiple buttons that insert content into a textarea. How can

Finally, I stumbled upon a script that enables undo/redo functionality for programmatically inserted text. You can find it here. If you want to check out the original script demo, click here. Here is the initial script: <div class="snippet" data-lang= ...

Sending JavaScript functions to PHP files via Ajax

My Current Project: I am currently developing a script that provides users with choices and generates new options based on their selections. To achieve this, I have created two scripts - one for the HTML structure of my page and another for fetching serve ...

Steps for creating a mandatory tag description

I am a newcomer to the world of WordPress, and my goal is to make a tag's description a required field on my custom theme for WordPress 4.5.2. I have attempted three different approaches, all of which have been unsuccessful. I would greatly appreciat ...

Troubleshooting route problems between AngularJS and Wordpress

After delving into AngularJS for a few weeks, I've been gaining valuable insights on Single Page Applications (SPAs). Since Angular is primarily front-end and requires a third-party data source to fetch information from a database, I decided to incorp ...

Error encountered in jsonwebtoken payload

Working on a web application with nodejs and angular cli, I have implemented JWT for login authentication. However, during the processing, I encountered the following error: Error: Expected "payload" to be a plain object. at validate (D:\Mean ...

It's frustrating when Redux triggers unnecessary re-rendering of a component

While working on my website with React and Redux, I encountered an issue regarding the image display within a card component. Initially, I have this card featuring a specific product. https://i.sstatic.net/CEoq7.png The functionality allows me to click on ...