Use REST api for editing directly

5160
4
04-25-2012 02:51 PM
ZorbaConlen
Occasional Contributor
Hi,
I need to edit a stand alone table in my javascript api application. I thought it woud be simple to do this with restful request, but having problems.

I have a proxy page set up and apparently working. Here is code snippet using public arcgis server resource. I have hard-coded the content for now. Once I get it working, the input will be dynamically generated.

//proxy page...
esri.config.defaults.io.proxyUrl = "../GISProxy/proxy.ashx";

//function to edit features
function addFeature(){
    var requestHandle = esri.request({
      url: "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1...",
      content: '[{"attributes" : {"agree_with_incident" : "2", "notes" : "problemo grande"}}]',
      handleAs: "json",
      load: requestSucceeded,
      error: requestFailed
  }, {useProxy:true});
}


The request fails. I suspect it is a problem with the content property. When I go to the above url and enter that string into the dialog, it is sucessful, but how to do this with ajax?

Thanks for any tips.
0 Kudos
4 Replies
nicogis
MVP Frequent Contributor
you set also post= true


{useProxy:true, usePost:true}

0 Kudos
ZorbaConlen
Occasional Contributor
Domenico,
Thanks for your response. It still appears there is a problem with the content. Looking at this in firebug, it appears that each character in the content string is seen as a separate parameter. See attachment. Do I need to pass in an object instead of a string maybe....
0 Kudos
nicogis
MVP Frequent Contributor
Zorba I have try and I haven't problem:


//proxy page...
        esri.config.defaults.io.proxyUrl = "ProxyPage/proxy.ashx";



        function requestSucceeded(response, io) {
            console.log("Succeeded: ", response);
        }

        function requestFailed(error, io) {
            console.log("Failed: ", error);
        }




            //function to edit features
            function addFeature(){
                var url = esri.urlToObject("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1/addFeatures?features=[{'attributes' : {'agree_with_incident' : '2', 'notes' : 'problemo grande1'}}]&f=json");
                var requestHandle = esri.request({
                url:url.path,
                content:url.query,
                callbackParamName:"callback",
                load:requestSucceeded,
                error:requestFailed
            }, {useProxy:true, usePost:true});
            }

0 Kudos
ZorbaConlen
Occasional Contributor
Domenico,
That works! Fantastic. Thanks much for the help with this.

Zorba
0 Kudos