跨域请求携带cookie

 
function ajaxPostRequestCipherMachine(url, param) {
        var url = url;
        var dict = {
            'ret' : false,
            'errmsg' : '请求失败'
        };
        var jsonData = param;
        $.ajax({
            type : "POST",
            url : url,
            async : false,
            data : jsonData,
            dataType : 'json',
            timeout : 10000,
            crossDomain:true, //设置跨域为true
            xhrFields: {
                withCredentials: true //默认情况下,标准的跨域请求是不会发送cookie的
            },
            success : function(obj) {
                dict = obj;
            },
            error : function(data) {
                alert(JSON.stringify(data));
            }
        });
        return dict;
    }

其中:

crossDomain:true, //设置跨域为true
xhrFields: {
     withCredentials: true //默认情况下,标准的跨域请求是不会发送cookie的
}

为要点

posted @ 2019-02-13 21:48  Samve  阅读(1071)  评论(0编辑  收藏  举报