我在nodejs中有以下代码。当我通过在浏览器中输入localhost:8120 / stS直接请求时设置cookie。但是,当我对同一个脚本进行ajax调用时,cookie不会被设置。我的代码有什么问题?
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs');
var GLOBALS = {};
function handler (req, res) {
if (req.url === '/stS')
{
console.log("Request received from server");
var Cookies = require("cookies");
var cookies = new Cookies( req, res);
cookies.set("blah","bleh");
console.log(res);
//res.writeHead( 200 , { "Location": "/" });
res.end( "Now let's check." );
}
}
app.listen(8120);