Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获类型错误:无法使用';在';操作员搜索';长度';在{array}_Javascript_Jquery_Json_Ajax - Fatal编程技术网

Javascript 未捕获类型错误:无法使用';在';操作员搜索';长度';在{array}

Javascript 未捕获类型错误:无法使用';在';操作员搜索';长度';在{array},javascript,jquery,json,ajax,Javascript,Jquery,Json,Ajax,这是我正在使用的脚本 <script> var user_lat, user_lng; var map; var url = "./rest/network"; function initMap() { map = new google.maps.Map(document.getElementById('map'), { center: { lat: 17, lng: 80 }, zoom: 5 }); $.post(u

这是我正在使用的脚本

<script>
var user_lat, user_lng;
var map;
var url = "./rest/network";
function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
    center: {
      lat: 17,
      lng: 80
    },
    zoom: 5
  });
    $.post(url,function(data,successStatus){
        $.each(data, function(index, value) {
            new google.maps.Marker({
              position: value,
              draggable: false,
              map: map,
              title: "cab"
            });
        });
    });     
}
</script>

如果数组格式有问题,那么第二个代码也不应该工作。但它正在发挥作用。我不知道问题背后的原因。ajax调用有什么问题吗?

数据
不是数组,而是字符串。使用
data=JSON.parse(数据)
之前执行code>。让我知道这是否有效。您应该确保发送的JSON文件具有正确的标题,并且只包含JSON数据。如果要导入结构化数据(如XML),则必须进行不同的转换。好的。我直接从java web服务返回字符串。现在我更改了字符串格式。向键值对中的键添加双引号。然后使用JSON.parse(数据)进行解析。现在它开始工作了。但实际上,我对发送服务响应的了解较少。每一条评论都对我很有帮助。谢谢@这里有些东西,谢谢。只要您的内容标题是
content-Type:application/json
,就可以在@TusharAs解决这个问题(只要它是格式正确的json字符串)。但是,嘿,很好,这起作用了!
<script>
var user_lat, user_lng;
var map;
var url = "./rest/network";
function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
    center: {
      lat: 17,
      lng: 80
    },
    zoom: 5
  });
    var data = [{lat:12.74711089,lng:79.98483278},
                {lat:18.0,lng:80.0},
                {lat:19.0,lng:78.0}];
    $.each(data, function(index, value) {
        new google.maps.Marker({
          position: value,
          draggable: false,
          map: map,
          title: "cab"
        });
    });

}
</script>