开发者

How can I use JQuery $.get to call a login page and save the authorisation cookie for subsequent requests?

I am using JQuery to invoke a service that is protected by a login page..

Client (Jquery/html5)...

$.get("http://localhost:8124/login", {'name':name, 'pwd':pass}, function(data) {...etc

Server (Node.js/Connect)

//...from authCheck
if ( url.pathname == "/login" && 
     url.query.name == "max" && 
     url.query.pwd == "max"  ) {
  req.session.auth = true;
  console.log("user:" + url.query.name + " - Login ok");
  next();
  return;开发者_高级运维
}

connect.createServer(
      connect.logger({ format: ':method :url' }),
      connect.cookieParser(),
      connect.session({ secret: 'foobar' }),
      connect.bodyParser(),
      authCheck,
      gameServer,
      defaultAuthorisedHandler
).listen(8124);

This works, but with subsequent $.get requests, the authorised session isn't recognised. The server code works when hitting it from a browser and it sets a cookie. I think i need to save the cookie from the first login request and pass it in subsequent requests. Can JQuery do this?

Michael

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜