+ Reply to Thread
Results 1 to 5 of 5

Thread: Use REST api for editing directly

  1. #1
    Zorba Conlen
    Join Date
    Mar 2012
    Posts
    42
    Points
    1
    Answers Provided
    1


    0

    Default Use REST api for editing directly

    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/addFeatures",
    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.

  2. #2
    Domenico Ciavarella

    Join Date
    Mar 2010
    Posts
    2,678
    Points
    458
    Answers Provided
    71


    0

    Default Re: Use REST api for editing directly

    you set also post= true

    Code:
    {useProxy:true, usePost:true}
    Studio A&T srl

    Domenico Ciavarella

    ESRI Certified
    Enterprise Geodatabase Management Associate 10.1
    Web Application Developer Associate 10.1

    My ArcGIS.com

    Blog: NicoGis

  3. #3
    Zorba Conlen
    Join Date
    Mar 2012
    Posts
    42
    Points
    1
    Answers Provided
    1


    0

    Default Re: Use REST api for editing directly

    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....
    Attached Files

  4. #4
    Domenico Ciavarella

    Join Date
    Mar 2010
    Posts
    2,678
    Points
    458
    Answers Provided
    71


    1

    Default Re: Use REST api for editing directly

    Zorba I have try and I haven't problem:

    Code:
    //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});
                }
    Studio A&T srl

    Domenico Ciavarella

    ESRI Certified
    Enterprise Geodatabase Management Associate 10.1
    Web Application Developer Associate 10.1

    My ArcGIS.com

    Blog: NicoGis

  5. #5
    Zorba Conlen
    Join Date
    Mar 2012
    Posts
    42
    Points
    1
    Answers Provided
    1


    0

    Default Re: Use REST api for editing directly

    Domenico,
    That works! Fantastic. Thanks much for the help with this.

    Zorba

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts