4 Replies Latest reply on Apr 30, 2012 2:12 PM by zconlen

    Use REST api for editing directly

    zconlen
      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.
        • Re: Use REST api for editing directly
          ciava.at
          you set also post= true

          
          {useProxy:true, usePost:true}
          
          
          • Re: Use REST api for editing directly
            zconlen
            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....
            • Re: Use REST api for editing directly
              ciava.at
              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});
                          }
              
              
              • Re: Use REST api for editing directly
                zconlen
                Domenico,
                That works! Fantastic. Thanks much for the help with this.

                Zorba