POST request to the backend service

4465
25
03-05-2018 03:40 PM
MansiShah
New Contributor III

Hello,

I am modifying an existing Web App Builder template and in order to complete the functionality of a widget I need it to make a connection to a backend service. When I pull up the service url, a form comes up that needs to be filled. I have the information for the form stored in a JSON. I want to pass that to the backend but I am getting errors on how to make the POST request. 

Here is what I've tried inside of a function: 

  $.ajax({
                method: "POST",
                url: "url to the backend service",
                data: jobIds,
                dataType: "json",
                success: function(){
                    console.log("Success!");
                }
            });
I have also tried to add the "dojo/request" and "dojo/json" dependencies but those give me errors and won't even let the widget start.
Have anyone else encountered this? Or is there another way to POST request and get a response from a backend service different from what I've coded up?
Thank you!!
0 Kudos
25 Replies
MansiShah
New Contributor III

Robert,

But when I do a test example and fill out the form in our backend service and hit submit, I get a proper json as a result of it: 

{  "jobIds": [   11924  ] }
0 Kudos
MansiShah
New Contributor III

Robert,

Does "yourinputparametername" refer to the label of the input box on the form in the backend service? So if I have multiple input boxes that need a value (because jobIds is an object where each property refers to an input box on the backend form), I would just need to add all of them in there one by one? 

0 Kudos
MansiShah
New Contributor III

Hey Robert,

I have a quick question. I see in the example code you wrote out above (with the code taking a ppin for an input  value), above the resultsDiv declaration, you are including or linking to a proxy via: 

esriConfig.request.proxyUrl = 'proxy/proxy.ashx';

 Is that necessary? Is a proxy setup needed for an esriRequest?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

It is if your request exceeds the string limit of a get request or you are using secured services

0 Kudos
Irishgeoff
New Contributor

You can save the form data using a form backend service 

 
0 Kudos
Irishgeoff
New Contributor

You can save the form data using a form backend service 

0 Kudos