我的申请上周工作正常。这是ajax请求:
$.ajax(
{
type: "GET",
url: "https://maps.googleapis.com/maps/api/directions/json?",
data: {
origin: start.replace(/ /g,'+'),
destination: end.replace(/ /g,'+'),
waypoints: 'optimize:' + false + '|' + waypts.join('|').replace(/ /g, '+'),
travelMode: google.maps.DirectionsTravelMode.DRIVING,
sensor: false
},
dataType: "json",
success: function(){alert("done");},
error: function(){ alert("error");}
});
今天它正在抛出这个错误:
Origin http://localhost is not allowed by Access-Control-Allow-Origin.
现在搜索过来了。我尝试在我的ajax请求中添加jsonp
。这产生了这个错误:
Uncaught SyntaxError: Unexpected token : json:2
我不明白这里出了什么问题。 提前谢谢。