Javascript 使用jQuery.ajax使用google places api添加地点
当我尝试将地点添加到Google Places时,我得到一个错误:Javascript 使用jQuery.ajax使用google places api添加地点,javascript,jquery,html,ajax,google-places-api,Javascript,Jquery,Html,Ajax,Google Places Api,当我尝试将地点添加到Google Places时,我得到一个错误: {"readyState":0,"responseText":"","status":0,"statusText":"error"} 这是我的密码: HTML: 我也一直在努力让它发挥作用。执行代码后,我在chrome调试器中注意到以下错误: Failed to load resource: the server responded with a status of 405 (Method Not Allowed) https
{"readyState":0,"responseText":"","status":0,"statusText":"error"}
这是我的密码:
HTML:
我也一直在努力让它发挥作用。执行代码后,我在chrome调试器中注意到以下错误:
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
https://maps.googleapis.com/maps/api/place/add/json?sensor=false&key={Key}
Failed to load resource: Origin http://localhost:8888 is not allowed by Access-Control Allow-Origin.
https://maps.googleapis.com/maps/api/place/add/json?sensor=false&{key}
XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/add/json?sensor=false&key={Key}.
Origin http://localhost:8888 is not allowed by Access-Control-Allow-Origin.
因此,google maps places API似乎不支持跨域,即使您已经在ajax对象中指定了它
幸运的是,有一个问题。不幸的是,它不支持添加地点或事件:(
我希望google在将来为places API添加更多支持。甚至可以通过jQuery.ajax()添加places吗?您能给我一个使用其他工具的替代解决方案吗?如果您不发布实际错误,我将无能为力。
$('#submitshop').click(function(){
$.ajax({
type: "POST",
url: "https://maps.googleapis.com/maps/api/place/add/json?sensor=true&key=asdEFasdBaasdasdasdMrN2ST5tRS5c",
crossDomain: true,
data: {
"location": {
"lat": 68.7425471,
"lng": 9.1370879
},
"accuracy": 50,
"name": "Test Shop!",
"language": "de"
},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(JSON.stringify(msg));
},
error: function (errormessage) {
alert(JSON.stringify(errormessage));
//{"readyState":0,"responseText":"","status":0,"statusText":"error"}
}
});
});
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
https://maps.googleapis.com/maps/api/place/add/json?sensor=false&key={Key}
Failed to load resource: Origin http://localhost:8888 is not allowed by Access-Control Allow-Origin.
https://maps.googleapis.com/maps/api/place/add/json?sensor=false&{key}
XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/add/json?sensor=false&key={Key}.
Origin http://localhost:8888 is not allowed by Access-Control-Allow-Origin.