23 views
Skip to first unread message

Ken Koontz

unread,
Aug 7, 2012, 1:43:35 AM8/7/12
to nod...@googlegroups.com
I have an 'action', which is an object that is the controlling code for incoming requests. My code looks like this:

    loginSubmit: function() {
        var self = this,
            session = generateCookie();

        user.on('loginValid', function(data) {
            client.sadd('sessions', session, redis.print);
            self.response.setHeader("Set-Cookie", ["session="+session+";Path=/"]);
            self.response.writeHead(200);
            self.response.end();
        }); 
        user.on('loginInvalid', function(data) {
            self.statusCode(404);
        }); 
        user.login(self.postData.email, self.postData.password);
    },  

'loginSubmit' is the action, it is executed when a request comes into /login/submit. Currently only AJAX requests touch loginSubmit, no page reload.

When I fill the form and hit submit, ajax fires and runs loginSubmit. If I fill out the form to emit 'loginInvalid', then fill it out again to emit 'loginValid', node throws an error:

http.js:686
    throw new Error('Can\'t render headers after they are sent to the client.'


Why? 
Reply all
Reply to author
Forward
0 new messages