简体   繁体   English

我想通过ajax调用从地图获取json数据

[英]i want to get json data from map through ajax call

i am calling map.php by passing lat long from ajax url i need to get map place response from map 我正在通过从ajax url传递lat长时间来调用map.php ,我需要从地图获取地图位置响应

function getinfo(lat,lng){
                $.ajax({
                  url:"map1.php?lat="+lat+"&lng="+lng,
                crossDomain:true,
                type:'POST',
                dataType:'application/json',
                data:"{}",
                  success:function(data){
                  var len = data.results.length;
                  for(var i=0;i<len;i++ ){
                      console.log(data.results[i]);
                  }
                }
                });
              };

error is 错误

response is not defined, function is not trigger 响应未定义,函数未触发

I think your result is probably not in JSON format, so when jQuery tries to parse it as such, it fails. 我认为您的结果可能不是JSON格式,因此,当jQuery尝试如此parse时,它会失败。 For more information about error you can catch the error with error: callback function. 有关错误的更多信息,可以使用error: callback function捕获错误。

error: function () {
 // your error handled inside this section
}

If you don't want to get JSON data response please remove dataType attribute. 如果您不想获取JSON数据响应,请删除dataType属性。

Other than that please check you backend return data object. 除此之外,请检查您的后端返回数据对象。 Also check the structure of your response data. 还要检查您的响应数据的结构。

The structure also can have error. 结构也可能有错误。 Also you can check your ajax call using chrome debugger and catch the results and errors. 您也可以使用chrome调试器检查ajax调用并捕获结果和错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM