美文网首页
ajax请求传递cookie

ajax请求传递cookie

作者: 小灰灰黢黑色 | 来源:发表于2018-12-10 16:13 被阅读0次

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

    }

});

相关文章

网友评论

      本文标题:ajax请求传递cookie

      本文链接:https://www.haomeiwen.com/subject/yrxdhqtx.html