var theData = [ { "geometry": { "x": -13316097.345, "y": 5861939.546999998 }, "attributes": { "Column1": "Value1", "Column2": "Value2" } } ]; $.ajax({ url: "http://myhostname/arcgis/rest/services/myservice/FeatureServer/0/addFeatures", dataType: 'json', type: 'POST', data: theData, success: function (data, textStatus, jqXHR) { // console.log('success'); console.log(data); console.log(textStatus); console.log(jqXHR) }, error: function (jqXHR, textStatus, errorThrown) { // 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) { // console.log('complete'); console.log(jqXHR); console.log(textStatus); } });
data: JSON.stringify(theData)
I don't know if you have found any solution for your question yet, but in case you are still interested, you can test the following:
var theData = {"features": [
{
"geometry": {
"x": -13316097.345,
"y": 5861939.546999998
},
"attributes": {
"Column1": "Value1",
"Column2": "Value2"
}
}
]};
another way that I'd recommend, and actually is worked for me, is to add the "features" parameter at the end of the url string:
var theData = [{ "geometry": { "x": -13316097.345, "y": 5861939.546999998 },
"attributes": { "Column1": "Value1", "Column2": "Value2" }
} ];
$.ajax({
url: "http://myhostname/arcgis/rest/services/myservice/FeatureServer/0/addFeatures" + JSON.stringify(theData)
, dataType: 'html' // the datatype must be html
, type: 'POST'
//, data: theData - remove this part
, success: function (data, textStatus, jqXHR) {
......
Make sure you specify the f and features parameters in the post body (The url has been changed in the code below, so do not try to use it):
$scope.addFeature= function(){
var url = "http://services6.arcgis.com/dD0xfCNJ6/arcgis/rest/services/US/FeatureServer/0/addFeatures";
var newFeature = {
"geometry" : {"x" : -122.679186, "y" : 45.539699},
"attributes" : {
"CandidateName" : "Hillary Clinton"
},
"spatialReference" : {
"wkid" : "4326"
}
};
var features = [];
features.push(newFeature);
var featuresString = JSON.stringify(features);
data = "f=json&features="+featuresString;
var config={
headers : {
'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
}};
$http.post(url, data, config)
.then(
function(response){
console.log(response);
},
function(response){
console.log(response);
}
);
}
Thanks Andrzej !!
I was having the same issue and tried to append f=json but that did not worked.
Once I added "f=json&features=" as per your suggestion/post it worked !!
For anyone encountering this with jquery.post(), make sure that you JSON.stringify the features part. So for example, this works:
var url = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Notes/FeatureServer/0/addFeatures";
var feature = {
"geometry" : {"x" : 2, "y" : 52},
"attributes" : {
"note" : "Hello!",
"name": "Guus"
},
"spatialReference" : {
"wkid" : "4326"
}
};$.post(url, {
features: JSON.stringify([feature]),
f: "json"
})
.done(function(results) {
console.log(results);
})
.fail(function(error) {
console.log(error);
});
(note that you have to put the one feature in an array)
I hope this will help!