Pergunta

I am writing a couchapp, which uses the couch.jquery.js library.

When I login to the site with ie8, i get a successful login (it returns ok, and a login id), but when I query the session, I get a userCtx.name of null (just like if the login didn't happen).

It would seem that explorer will not keep the cookie from the login. Does anyone have any info on this? I have tried J Chris's couchLogin.js library and written my own login scripts with the same problem.

The session code is:

$.couch.session({
    success: function(data) {
        console.log(JSON.stringify(data));
    }
});

Response from IE:

{"ok":true,"userCtx":{"name":null,"roles":[]},"info":{"authentication_db":"_users","authentication_handlers":["oauth","cookie","default"]}}

Response from Firefox / Chrome:

{"ok":true,"userCtx":{"name":"user1","roles":[]},"info":{"authentication_db":"_users","authentication_handlers":["oauth","cookie","default"],"authenticated":"cookie"}}
Foi útil?

Solução

I have solved this by editing jquery.couch.js, and adding cache:false to ajax call in the session function.

session: function(options) {
  options = options || {};
  $.ajax({
    cache: false,  //disable caching for IE
    type: "GET", url: this.urlPrefix + "/_session",
    beforeSend: function(xhr) {
        xhr.setRequestHeader('Accept', 'application/json');
    },
    complete: function(req) {
      var resp = $.parseJSON(req.responseText);
      if (req.status == 200) {
        if (options.success) options.success(resp);
      } else if (options.error) {
        options.error(req.status, resp.error, resp.reason);
      } else {
        throw "An error occurred getting session info: " + resp.reason;
      }
    }
  });
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top