我正在尝试发送跨域域并添加自定义"授权"标头.请参阅下面的代码.
错误:
XMLHttpRequest无法加载{url}.请求标头字段Access-Control-Allow-Headers不允许授权.
function loadJson(from, to) {
$.ajax({
//this is a 'cross-origin' domain
url : "http://localhost:2180/api/index.php",
dataType : 'json',
data : { handler : "statistic", from : from, to : to
},
beforeSend : setHeader,
success : function(data) {
alert("success");
},
error : function(jqXHR, textStatus, errorThrown) {
alert("error");
}
});
}
function getToken() {
var cookie = Cookie.getCookie(cookieName);
var auth = jQuery.parseJSON(cookie);
var token = "Token " + auth.id + ":" + auth.key;
}
function setHeader(xhr) {
xhr.setRequestHeader('Authorization', getToken());
} …Run Code Online (Sandbox Code Playgroud)