weixin_33714884 2017-08-11 04:44 采纳率: 0%
浏览 88

Node.js上的Ajax请求错误

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

  • 写回答

1条回答 默认 最新

  • weixin_33682719 2017-08-11 06:20
    关注

    Cookies can not be shared across sites, this includes sites on the same domain but using different ports.

    评论

报告相同问题?

悬赏问题

  • ¥15 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。