1、原生ajax請求方式:
1 var xhr = new XMLHttpRequest();
2 xhr.open("POST", "", true);
3 xhr.withCredentials = true; //支持跨域發(fā)送cookies
4 xhr.send();
2、jquery的ajax的post方法請求:
$.ajax({
type: "POST",
url: "",
dataType: 'json',
// 允許攜帶證書
xhrFields: {
withCredentials: true
},
// 允許跨域
crossDomain: true,
success:function(){
},
error:function(){
}
})
3、服務(wù)器端設(shè)置:
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: ");