开发者

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

开发者 https://www.devze.com 2023-03-28 12:40 出处:网络
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

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

精彩评论

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