3

Trying to make a new feature on a map. I got the code like this where i`m using atm hardcoded coordinates:

function addFeature(browserEvent, dataSource) {
  //add feature
  var url = dataSource + '/0/addFeatures';
  var coordinate = browserEvent.coordinate;
  var x = coordinate[0];
  var y = coordinate[1];
  //console.log('De locatie is ' + coordinate);

  var jsonTemp = [{
    'geometry': {
      'x': 248460.375,
      'y': 440990.21880000085
    },
    'attributes': {
      'relcp86d_': 0,
      'relcp86d_i': 99999,
      'symbol': 77,
      'polygonid': 1,
      'scale': 1,
      'angle': 10,
      'omschrijvi': 'Testobject'
    }
  }];

  var jsonTempStringified = JSON.stringify(jsonTemp);
  var jsonTempStringifiedParsed = JSON.parse(jsonTempStringified);

  $.ajax({
    url: url,
    dataType: 'json',
    type: 'POST',
    data: jsonTempStringifiedParsed,
    success: function(data) {
      console.warn(data);
    },
    error: function(xhr, ajaxOptions, thrownError) {
      console.warn(xhr);
      console.warn(thrownError);
      //console.warn(ajaxOptions);
    }
  });

}

I tried to use this exact json in the browser and it works(Link) but using it via this it's giving me errors and i tried all kind of things. As you can see from a previous post i really have problems with json and the arcgis server services.

Error code is:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
Stacktrace:
ajaxConvert@http://localhost:8080/dist/app.js:9465:19
done@http://localhost:8080/dist/app.js:9933:15
[10]</</</<.send/callback/<@http://localhost:8080/dist/app.js:10225:9

I also tried to remove the [] doesn't help it keeps having the same problem. As you can see i have also tried with or without or even double parse/stringify just nothing helps.

2

I got the answer, i found out my data was incorrect. The data should be like this

data: 'f=json&features=' + jsonTempStringified,

For me this worked.

| improve this answer | |

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