ajax請求傳遞cookie
服務器端要做些返回頭的修改:
response.setHeader("Access-Control-Allow-Credentials","true");
前端ajax請求可以設置如下:
$.ajax({
url:_url,
type:"get",
data:"",
dataType:"json",
xhrFields: {
withCredentials: true
},
success: function(){}
})
當需要對全局進行配置時可以設置:
$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
options.xhrFields = {
withCredentials: true
}
});
