访问-控制-允许-原产地错误发送jQueryPost到GoogleAPI
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.
<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 -->温温酱
相关分类