简体   繁体   中英

Ajax request error on Node.js

I have a node.js server running on port 3000 and in my index.html file on that server, I send a Ajax request to apache2 server on port 80 to retrieve the current cookie on the site. However, I get no cookie response even though I see the cookie on my browser. My Ajax request on index.html :

$.ajax ({
        type: "GET",
        url: "http://103.57.220.117:80/chatroom/api/auth",
        async: false,
        global: false,
        processData: false,
        contenType: "application/json",
        data: "",
        success: function(r) {
            console.log(r)
        },
        error: function(r) {
            console.log(r)
        }
}); 

In my index.php endpoint on my api file:

if ($_SERVER['REQUEST_METHOD'] == 'GET') {

if ($_GET['url'] == 'auth') {

    $cookie= $_COOKIE['SNID'];
    echo '{ "cookie" : '.$cookie.' }';
    http_response_code(200);

}

}

The api response with the 200 code but no cookie

However, on the browser there is cookie displayed and active ( cookie on browser )

Is there any way to fix this? I really need solution because this is very important for my school project

Cookie不能在站点之间共享,这包括同一域中但使用不同端口的站点。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM