weixin_33726943 2017-03-31 14:09 采纳率: 0%
浏览 62

Object.toString()-> [对象对象]

The following code send by using Ajax a json :

var geojson = new Object();
geojson["type"] = "FeatureCollection";
geojson["zone_type"] = "Zone";
$.ajax({
  url : url,
  type : 'POST',
  data : geojson,
  dataType : 'json',
});

However, when I ask in the console "geojson" and when I look the request in the network :

geojson = "[object Object]"

Actually, I should have the object :

geojson = {type:FeatureCollection,zone_type:Zone}

Shouldn't I ?

  • 写回答

1条回答 默认 最新

  • weixin_33728708 2017-03-31 14:21
    关注
    var geojson = new Object();
    geojson["type"] = "FeatureCollection";
    geojson["zone_type"] = "Zone";
    $.ajax({
      url : url,
      type : 'POST',
      data : JSON.stringify(geojson),
      dataType : 'json',
    });
    

    If I add JSON.stringify(geojson) indeed, I get correctly :

    geojson = {"type":"FeatureCollection","zone_type":"warning_zone"}
    

    Thank you very much @SLYcee

    评论

报告相同问题?