访问-控制-允许-原产地错误发送jQueryPost到GoogleAPI我读了很多关于“访问-控制-允许-起源”错误的文章,但是我不明白我必须修复什么:我在玩Google主持人API,但是当我试图增加新的意甲我收到:XMLHttpRequest cannot load
&data%5Bname%5D=Eating+Healthy+%26+Cheap&data%5BvideoSubmissionAllowed%5D=false. Origin [my_domain] is not allowed by Access-Contro
l-Allow-Origin.我尝试使用和不使用回调参数,我尝试添加‘访问控制-允许-原产地*’到标题。如果应用,我不知道如何在这里使用$.getJSON,因为我必须添加授权头,而且我不知道如何在$.ajax:/有光线照亮这个黑暗的美国吗?这就是密码:<script src="http://www.google.com/jsapi"></script><script type="text/javascript">
var scope = "https://www.googleapis.com/auth/moderator";var token = '';function create(){
if (token == '')
token = doCheck();
var myData = {
"data": {
"description": "Share and rank tips for eating healthily on the cheaps!",
"name": "Eating Healthy & Cheap",
"videoSubmissionAllowed": false
}
};
$.ajax({
url: 'https://www.googleapis.com/moderator/v1/series?key='+key,
type: 'POST',
callback: '?',
data: myData,
datatype: 'application/json',
success: function() { alert("Success"); },
error: function() { alert('Failed!'); },
beforeSend: setHeader });}function setHeader(xhr) {
xhr.setRequestHeader('Authorization', token);}function doLogin(){
if (token == ''){
token = google.accounts.user.login(scope);
}else{
alert('already logged');
}}function doCheck(){
token = google.accounts.user.checkLogin(scope);
return token;}</script>...
...<div data-role="content">
<input type="button" value="Login" onclick="doLogin();">
<input type="button" value="Get data" onclick="getModerator();">
<input type="button" value="Create" onclick="create();"></div><!-- /content -->
3 回答
温温酱
TA贡献1752条经验 获得超4个赞
<?php header('Access-Control-Allow-Origin: *'); ?>
- 3 回答
- 0 关注
- 440 浏览
添加回答
举报
0/150
提交
取消