ajax请求传递cookie

2018-12-10  本文已影响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

    }

});

上一篇 下一篇

猜你喜欢

热点阅读