setRequestHeader设置头部信息问题!!
var _xhr = null;
try{
_xhr = new window.XMLHttpRequest(); //创建XML HttpRequest对象
//_xhr.setRequestHeader("Origin", '*');
} catch (ex){
try{
_xhr = new ActiveXObject('Msxml2.XMLHTTP'); //低版本兼容
//_xhr.setRequestHeader("Origin", '*');
} catch(ex){
}
};
_xhr.onreadystatechange = function(){ //事件
try{
if(_xhr.readyState == 4 && _xhr.status == 200){ // readyState从0到4接受完成 并且status 表示http状态 为200者成功 (如在readyState不大于>返回异常)
callback(_xhr.responseText); //接受返回指定响应文本体(字符头部)
}
} catch (ex){
}
};
//open(method, url, async, username, password)
/*
**method请求方式 (get,post,head)
**async为false表示同步
*/
_xhr.open('get', url,true);
_xhr.setRequestHeader("Origin",'*');
_xhr.send(null);
报错:Refused to set unsafe header "Origin" 要怎么设置啊!请求方要求 只要在请求头里面加上 Origin: * 字段, 我们的服务器就会返回Access-Control-Allow-Origin: *
Origin: * 这个“*”可以是任何字段