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,angularJs/ajax跨域请求携带cookies的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: css文字下滑,CSS3 文本下落渐变动
- 下一篇: django ajax文件上传,djan