加载Google JS api时阻止了跨来源请求
Cross Origin Request Blocked while loading Google JS api
我遇到了一种前所未有的奇怪情况
我的代码目标:我正在使用Parse.com作为后台制作一个网络应用程序,并希望使用谷歌图表在网页中添加一些饼图。
我做了什么:正如文档中所述,我加载了GoogleJSapi,使用标签:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
问题从这里开始。在我打开包含此标记的页面后,页面加载失败(从某种意义上说,它被卡在Read www.google.com...
上,我只能看到一个白色屏幕)。我打开控制台,发现以下消息:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.parse.com/1/classes/MyClass. This can be fixed by moving the resource to the same domain or enabling CORS.
这里的MyClass
是我在Parse后端创建的类的名称,在页面加载过程中会调用一个函数从中获取一些数据。
我尝试在一个单独的页面中加载JS api,它成功地工作了。有什么办法吗?在我的情况下,重要的是同时加载Parse.com的API和Google的JS API。有什么帮助吗?非常感谢。
附言:以下脚本是在页面加载过程中加载的:
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.18.min.js"></script>
<script type="text/javascript" src="myquery.js"></script>
<script type="text/javascript" src="userquery.js"></script>
jquery.js
是缩小的jQuery库。"myquery.js"和userquery.js
是我自己编写的js文件。
您确定正在使用JSONP吗?我甚至在本地主机上也使用过谷歌的jsapi(尽管没有使用parse)。您可以将解析时的数据公开为web服务,然后可以对解析服务进行AJAX JSONP调用。
这对我来说很有效,没有任何问题,我在本地主机和各种域上都尝试过。
var jsonData = jQuery.ajax({
type: 'POST',
url: base_url+"index.php/<url>?callback=?",
dataType:"jsonp",
data: {userID : uID},
async: false
}).responseText;
var options = {
title: 'Title',
hAxis: {title: 'X'},
vAxis: {title: 'Y'}
};
//create table for google visualization
var datatable = new google.visualization.DataTable();
//add rows and column to datatable
....
//draw chart
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data1, options);
相关文章:
- google在类内映射javascript directionsService.route请求:将类实例传递给回调函数
- 是Google自定义搜索API的客户端请求数量有限
- Google Maps JavaScript API v3:getDetails(请求,回调),用于多个位置
- 从 Google 云端硬盘请求文件元数据时缺少“downloadUrl”参数
- 在 Google 云端硬盘 API 请求中使用参数
- Google Chrome扩展HTTPS Ajax请求
- URL中用户@的几个请求导致“;违反政策通知;来自Google AdSense
- 使用Google Drive和Angularjs时,不允许使用请求标头字段Accept Encoding
- Google Chrome扩展Http请求
- JavaScript中的Google Drive API请求
- 在 ajax 请求后执行 Google AdWords 转化跟踪代码
- AJAX对Google Maps API的请求停止工作
- 如何“减少请求序列化”并提高Google页面速度
- 对 Google API HTTP 请求使用动态变量
- 跟踪 Google 可视化 API 请求中的事件
- 为什么此 Google 日历 API 请求不返回开始时间等事件数据
- Google Geocoder 在 url 和 javascript 请求之间有不同的结果
- 使用 xhr 请求 Google Place API 遇到了 CORS 问题
- 如何使用 Javascript 中的 API 密钥正确请求 Google Link Shortener API 的 XM
- 批量请求Google Places(Javascript v3)