记录遇到的请求接口不会自动带上cookie的问题

274 阅读1分钟

跨域

如果存在跨域问题,请求接口是不会自动带上cookie的,解决办法如下:

$.ajax({
    url: "http://localhost:8080/orders",
    type: "GET",
    xhrFields: {
        withCredentials: true
    },
    success: function (data) {
        render(data);
    }
});

http与https

当前端页面地址是http,接口是https的话,后端不能存上cookie,同时请求接口也不会带上cookie