解決ajax跨域請(qǐng)求數(shù)據(jù)cookie丟失問(wèn)題

字號(hào):


    前端:
    以jquery為例:
    需要加入
    代碼如下:
    xhrfields: {
    withcredentials: true
    },
    crossdomain: true,
    $.ajax({
    type: posttype,
    url: url,
    data: postdata || '',
    xhrfields: {
    withcredentials: true
    },
    crossdomain: true,
    success: function () {
    successcallback.apply(scope || this, arguments);
    },
    failurecallback: function () {
    failurecallback.apply(scope || this, arguments);
    },
    datatype: datatype
    });
    服務(wù)器端:
    以php為例:
    代碼如下:
    header(access-control-allow-credentials: true);
    header('access-control-allow-origin: );
    根據(jù)自己的情況而定
    以上所述就是本文關(guān)于解決ajax跨域請(qǐng)求數(shù)據(jù)時(shí)cookie丟失的處理方案,希望大家能夠喜歡。