I have the following piece of code in nodejs . The cookie is set when i make a direct request by typing in localhost:8120/stS in the browser . However when i make an ajax call to the same script , the cookie does not get set . What is the problem with my code ?
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);