出处
原生ajax请求方式:
var xhr = new XMLHttpRequest(); xhr.open("POST","http://xxxx.com/demo/b/index.PHP",true); xhr.withCredentials = true; //支持跨域发送cookies xhr.send();
jquery的ajax的post方法请求:
$.ajax({
type: "POST", url: "http://xxx.com/api/test", dataType: ‘jsonp‘, xhrFields: { withCredentials: true }, crossDomain: true,
success:function(){
},
error:function(){
}
})
服务器端设置:
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: http://www.xxx.com");
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。