ajax请求传递cookie

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
    }
});

  

我自横刀向天笑,哈哈哈哈哈哈哈!
原文地址:https://www.cnblogs.com/yinian/p/8371746.html