Mike-N88
Mike-N88

Reputation: 35

AJAX with json call to an ArcGIS service not working

I`m trying to update some data in a rest service via a rest call. For some reason my code isn't working, the code i use is:

  var jsonTemp = [{
    attributes : {
      'objectId' : str.objectid,
      'relcp86d_' : str.relcp86d_,
      'relcp86d_i' : str.relcp86d_i,
      'symbol' : str.symbol,
      'polygonid' : str.polygonid,
      'scale' : str.scale,
      'angle' : str.angle,
      'omschrijvi' : str.omschrijvi
    },
    geometry : {
      'x' : str.geometry.flatCoordinates[0],
      'y' : str.geometry.flatCoordinates[1]
    }
  }];

  jsonTemp = JSON.parse(JSON.stringify(jsonTemp));
  console.log('jsonTemp: ', jsonTemp);


  $.ajax({
    url: url,
    dataType: 'json',
    type: 'POST',
    data: jsonTemp,
    success: function(data) {
      console.log('success ', data);
    },
    error: function(xhr, ajaxOptions, thrownError) {
      alert(xhr.status);
      alert(thrownError);
    }
  });

Then if i check the response it looks like some kind of object is in the error code so i don't know what to do. The error looks like this:

Error  Object { readyState: 4, getResponseHeader: [9]</</<.ajax/jqXHR.getResponseHeader(), getAllResponseHeaders: [9]</</<.ajax/jqXHR.getAllResponseHeaders(), setRequestHeader: [9]</</<.ajax/jqXHR.setRequestHeader(), overrideMimeType: [9]</</<.ajax/jqXHR.overrideMimeType(), statusCode: [9]</</<.ajax/jqXHR.statusCode(), abort: [9]</</<.ajax/jqXHR.abort(), state: [9]</</<.Deferred/promise.state(), always: [9]</</<.Deferred/promise.always(), catch: [9]</</<.Deferred/promise.catch(), 9 meer… }

--edit

I was trying to do this via OpenLayers3 first but that didn't work so that's why i try it via this way now. This is the error code i get using thrownError

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Upvotes: 0

Views: 438

Answers (1)

Jaime
Jaime

Reputation: 323

Try this

 $.ajax({
    url: url,
    dataType: 'json',
    type: 'POST',
    data: jsonTemp,
    success: function(data) {
      console.log('success ', data);
    },
    error:function(jqXHR, textStatus, msg){
      console.log('Error ', textStatus);
    }
  });

Upvotes: 2

Related Questions