调用百度地图Web服务API,url正确且能用浏览器看到返回的数据,用js接收不到数据,求大神解释
通过百度地图web服务api获取起始点的所有经过的地点坐标,在处理返回数据的时候 xmlHttp.readyState == 4) if (xmlHttp.status 总是等于0,不是200,responseText为空前面readyState=4表示已经完成了,很不是理解求大神解释
//通过起始坐标来画路线图
function GetDataByApi() {
var startPoint = new BMap.Point(120.356545, 36.117578);
var endPoint = new BMap.Point(120.433583, 36.123175);
var data="mode=driving&origin=" + startPoint.lat + "," + startPoint.lng + "&destination=" + endPoint.lat + "," + endPoint.lng + "&origin_region=青岛&destination_region=青岛&output=json&ak=rLhTKL4CCeaVGGjs4zcSGajP";
var url = "http://api.map.baidu.com/direction/v1";
var surl=url+"?"+data;
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("get", "http://api.map.baidu.com/direction/v1?mode=driving&origin=36.117578,120.356545&destination=36.123175,120.433583&origin_region=青岛&destination_region=青岛&output=json&ak=rLhTKL4CCeaVGGjs4zcSGajP", true);
xmlHttp.onreadystatechange=ShowResult;
xmlHttp.send(null);
//回调方法
function ShowResult() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200 ) {
alert(xmlHttp.responseText);
}
}
}