0

I have to modifiy an app. This app must update and add data to feature in an ArcGIS Server service. I know that with ArcGIS JavaScript API is very easy but this app is build with Leaflet and others things and I can't change.

I'm trying to do it with ajax, this is my code

$.ajax({  
            url: featureServiceUrl + "/updateFeatures",  
            dataType: 'json',  
            type: 'POST',  
            data: "features:"+poiToAdd+"&f=json",
            success: function (data, textStatus, jqXHR) {  
                debugger;
                //  
                console.log('success');  
                console.log(data);  
                console.log(textStatus);  
                console.log(jqXHR)  
            },  
            error: function (jqXHR, textStatus, errorThrown) {  
                debugger;
                //  
                console.log('error'); //<-- the response lands here ...  
                console.log(jqXHR); //<-- the console logs the object  
                console.log(textStatus); //<-- the console logs 'parsererror'  
                console.log(errorThrown); //< -- the console logs 'SyntaxError {}'  
            },  
            complete: function (jqXHR, textStatus) {  
                debugger;
                //  
                console.log('complete');  
                console.log(jqXHR);  
                console.log(textStatus);  
            }  
        });  

PoiToAdd is the data to modify, this data is correct because when I introduce it in this windows

enter image description here

the data is updated in my server, but with ajax code returns an error, that the data isn't correct. I also try with XMLHttpRequest I have to say that this not is my code, but this work fine in other app from my company

update: function(updateFeature,callback){
    var updateparams = "features="+updateFeature+"&f=json";
    var updateurl=this.url+"/updateFeatures";
    var http;
    debugger;
    if (window.XMLHttpRequest){
        http=new XMLHttpRequest();
    }
    else {
        http=new ActiveXObject("Msxml2.XMLHTTP");
    }
    http.open("POST", updateurl, true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.onreadystatechange = function() {//Call a function when the state changes.
        if(http.readyState == 4 && http.status == 200) {

            if (callback) { callback(http.responseText); }
        }
    }
    http.send(updateparams);
}, //end UPDATE

Here Updatefeatures is == to PoiToAdd and this.url is the featureservice url, now when i execute this doesn't return any error, but the data isn't updated

1 Answer 1

1

I have just solved my problem - it was the next

my data had this simbol "%" "&" and "+" and this done that the ajax and XMLHttpRequest didn't work fine. One time i have changed this, the code work.

This symbol create an error because this symbol are reserved to the URL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.