使用以下代码请求时出现Cross-Origin Request Blocked:
错误。
$.ajax({
url: 'https://www.google.com/m8/feeds/contacts/default/full?access_token=' + token.access_token,
type: 'POST',
crossOrigin: true,
crossDomain: true,
Origin: 'http://localhost',
Host: 'www.google.com',
xhrFields: {
withCredentials: true
},
dataType: 'xml',
'Gdata-version': '3.0',
'Content-Type': 'application/atom+xml',
'body': xml,
}).done(function(data) {
console.log(data);
});
});
GET
方法使用jsonp(不是POST
方法)检索联系人作为数据类型而没有任何错误,但在POST
方法中我收到错误。
答案 0 :(得分:-1)
很简单,您应首先设置服务器 http响应标题。与您的前端JavaScript代码无关。您需要返回此标题:
Access-Control-Allow-Origin:*
或
Access-Control-Allow-Origin:your domain