CORS request - why are the cookies not sent?

后端 未结 1 449
孤街浪徒
孤街浪徒 2020-11-29 23:59

I have a cross-domain AJAX GET which gets pre-flighted successfully, but the cookies don\'t get attached to the GET request. When the user clicks a log in button, a POST is

相关标签:
1条回答
  • 2020-11-30 00:14

    The issue was with the jQuery calls - it seems since 1.5 withCredentials should be specified as:

            $.ajax("http://localhost:3000/users/current", {
                type: "GET",
                contentType: "application/json; charset=utf-8",
                success: function(data, status, xhr) {
                    hideAllContent();
                    $("#sign_out_menu_item").show();
                    $("#sign_in_menu_item").hide();
                    $("#welcome").text("Welcome " + data["username"] + "!");
                    $("#welcome").show();
                },
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true
            });
    
    0 讨论(0)
提交回复
热议问题