JSON 请求帮助
首先,如果 Google Places API 允许 JSONP 请求,我会使用 jQuery 执行此操作,但我使用的是标准 XMLHttpRequest:
function load() {
var req = new XMLHttpRequest();
req.open('GET', 'https://maps.googleapis.com/maps/api/place/details/json?reference=CnRhAAAARMUGgu2CeASdhvnbS40Y5y5wwMIqXKfL-n90TSsPvtkdYinuMQfA2gZTjFGuQ85AMx8HTV7axABS7XQgFKyzudGd7JgAeY0iFAUsG5Up64R5LviFkKMMAc2yhrZ1lTh9GqcYCOhfk2b7k8RPGAaPxBIQDRhqoKjsWjPJhSb_6u2tIxoUsGJsEjYhdRiKIo6eow2CQFw5W58&sensor=true&key=xxxxxxxxxxxxx', false);
req.send(null);
if (req.status == 200) {
dump(req.responseText);
}
}
我在跨域源安全问题上遇到问题,但我真正要问的是,如果这是从 Google Places API 请求 JSON 的最简单方法吗?
我正在寻找最简单的方法来执行此操作,而无需设置本地代理来处理跨域来源的内容。
或者是否有另一个使用常规 JSON 请求的 javascript 工具包?
First off, I would be doing this with jQuery if the Google Places API would allow JSONP requests, but instead I am using a standard XMLHttpRequest:
function load() {
var req = new XMLHttpRequest();
req.open('GET', 'https://maps.googleapis.com/maps/api/place/details/json?reference=CnRhAAAARMUGgu2CeASdhvnbS40Y5y5wwMIqXKfL-n90TSsPvtkdYinuMQfA2gZTjFGuQ85AMx8HTV7axABS7XQgFKyzudGd7JgAeY0iFAUsG5Up64R5LviFkKMMAc2yhrZ1lTh9GqcYCOhfk2b7k8RPGAaPxBIQDRhqoKjsWjPJhSb_6u2tIxoUsGJsEjYhdRiKIo6eow2CQFw5W58&sensor=true&key=xxxxxxxxxxxxx', false);
req.send(null);
if (req.status == 200) {
dump(req.responseText);
}
}
I am having problems with cross-domain origin security stuff, but what I am really asking is if this is the easiest way to go about requesting JSON from the Google Places API?
I am looking for the easiest way to do this without having to setup a local proxy to deal with cross domain origin stuff.
Or is there another javascript toolkit that uses regular JSON requests?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
jQuery 不限于 JSONP。
请注意:
因此您可能必须切换到异步请求。
jQuery is not limited to JSONP.
Note that:
so you may have to switch to asynchronous requests.