使用 google place api 添加一个地点,使用 jQuery.ajax 进行定位
Adding a place with google places api using jQuery.ajax
当我尝试向 Google 地点添加地点时,出现错误:
{"readyState":0,"responseText":"","status":0,"statusText":"error"}
这是我的代码:
.HTML:
<form id="addShopForm">
...
<a type="submit" id="submitshop">Submit</a>
</form>
Jquery:
$('#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"}
}
});
});
我也
一直在努力让它工作。执行代码后,我在 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.
因此,似乎谷歌地图放置API不支持跨域,即使您已在ajax对象中指定了它。
幸运的是,有一个客户端JavaScript库。不幸的是,它不支持:(添加地点或事件。
我希望谷歌将来为地方API添加更多支持。
相关文章:
- 如何使用jQuery自动打开页面上的所有链接
- 如何使用jquery在填充自动完成的值后使文本框只读
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- 如何在Angular2中使用jQuery插件
- 如何使用jQuery选择下拉列表的值
- 使用JQuery解析JSON嵌套数组
- 在不使用JQuery的情况下隐藏DOM中的选定元素
- 如何使用jquery处理php循环通过元素
- 使用jquery将mysql数据获取到新的表行中
- 如何使用jquery Validation验证Formspread
- 是否有任何方法可以使用jQuery替换在数组中定义值的文本
- 使用jQuery动态添加表并在其中动态添加行
- 使用jquery在单击时在单元格中输入值
- 如何使用jQuery在动画中期加速动画
- 如何使用jquery强制一个单词更改大小写等以保留品牌
- 在不使用jquery的情况下查找页面中的所有锚点并附加函数
- 使用JQuery的动态上下文菜单
- 使用jQuery以红色和黑色闪烁文本
- 如何使用jquery更改html中的背景颜色
- 使用jQuery从原始页面内容创建iframe