angularjs ajax header,angularJs/ajax跨域请求携带cookies

前后端分离时候,当前端测试不在同一个域时候,前端使用ajax请求时,ajax默认不会将cookies保存,而且也不会发送cookie到服务端,

此时在请求方法中加入粗体部分即可,当然存取cookies的时候也要加进去(比如登录的时候)

-------------------------------------------------ajax--------------------------------------------------------------

$.ajax({

type: "GET",

url: "http://dddd",

dataType: "json",

xhrFields: {

withCredentials: true

},

crossDomain: true,

success: function(data){

}

});

-----------------------------------------------------angularJs-----------------------------------------------------------

$http.post("http://a.domain.com/Api/Product", { productId:3}, {

withCredentials:true,    params: { name:"Ray"},

headers: {'Authorization':"这个不重要"}})

.success(function(data){//TODO});

你可能感兴趣的:(angularjs,ajax,header)