How to add feature to service layer?

511
4
Jump to solution
10-27-2017 10:17 AM
EdgarMontes
New Contributor II

I am trying to add a feature to a service layer using ajax post. I get a 200 back but when i query the service, the post feature does not show. I am using ArcGis Online 1.5.1

service:

https://services2.arcgis.com/qvkbeam7Wirps6zC/ArcGIS/rest/services/service_e85611f4185545fab4a50ca81... 

0 Kudos
1 Solution

Accepted Solutions
EdgarMontes
New Contributor II

I finally fixed it, for some reason it wanted me to post my data as a string in the url, instead of withing my request body. Here is the code for anyone that wants to try this:

const url = 'https://services2.arcgis.com/qvkbeam7Wirps6zC/ArcGIS/rest/services/service_e85611f4185545fab4a50ca81... encodeURIComponent(JSON.stringify(data)) +'&f=json';


var request = new Request(url, {
method: 'POST',
body: '',
headers: new Headers()
});

fetch(request)
.then((resp) => {
console.log(resp);
console.log(resp.status);
if(resp.status === 200){
console.log('item submitted');
}
});

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Edgar,

  Can you elaborate as to why you are attempting to add the feature using AJAX instead of the FeatureLayer.applyEdits([new features]) method?

0 Kudos
EdgarMontes
New Contributor II

I have light a custom application with a form that post to our service. Do I need arcgis.js to do any edits to services? 

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

No it should not be necessary. can you post the code you are using for the AJAX Post?

0 Kudos
EdgarMontes
New Contributor II

I finally fixed it, for some reason it wanted me to post my data as a string in the url, instead of withing my request body. Here is the code for anyone that wants to try this:

const url = 'https://services2.arcgis.com/qvkbeam7Wirps6zC/ArcGIS/rest/services/service_e85611f4185545fab4a50ca81... encodeURIComponent(JSON.stringify(data)) +'&f=json';


var request = new Request(url, {
method: 'POST',
body: '',
headers: new Headers()
});

fetch(request)
.then((resp) => {
console.log(resp);
console.log(resp.status);
if(resp.status === 200){
console.log('item submitted');
}
});

View solution in original post

0 Kudos