我使用 mapquest 的免费地理编码 API
我想检查请求是否成功,但没有返回任何数据。
我在表单字段中输入“vdfsbvdf54vdfd”(只是一个愚蠢的字符串)作为地址。我期待这样的警报“对不起,输入错误”。警报永远不会发生。
这是我的代码片段
$.ajax({
type: "POST",
url: "`http://open.mapquestapi.com/geocoding/v1/address?key=012`",
data: { location: ad, maxResults: 1}
})
.done(function( response ) {alert(response);
var geoclng = response.results[0].locations[0].latLng.lng;
var geoclat = response.results[0].locations[0].latLng.lat;
if (geoclng=="") {alert("Sorry, wrong input");}
//now use lon/lat on map etc
)}
我试过了if (geoclng=="") {alert("Sorry, wrong input");}
还if (response.length=0) {alert("Sorry, wrong input");}
并且if ($.isEmptyObject(response)) {alert("Sorry, wrong input");}
并且警报永远不会发生。
如果它有帮助,当我提醒我得到的回复时object Object
。
提前致谢