standard technique for getting post parameters?

2 views
Skip to first unread message

Jason Wang

unread,
Dec 28, 2009, 2:46:51 PM12/28/09
to nodejs
Hi all,

I was just wondering whether there are any standard techniques for
getting post parameters from the body. Here is something i copied from
nodewiki:

function getPostParams(req, callback){
var body = '';
sys.puts('in here');
req.addListener('body', function(chunk){body += chunk;})
.addListener('complete', function(){
callback(unescape(body.substring(8).replace(/\+/g,' ')));
});
}

It doesn't seem to work, and the process just hangs (in the callback,
i just did sys.puts('done'); sys.puts(content); where content is the
sole parameter for the callback. Only 'done' gets printed).

Is there any better way of doing it?

Any enlightenment would be much appreciated!

Elijah Insua

unread,
Dec 28, 2009, 4:18:10 PM12/28/09
to nod...@googlegroups.com

  var body = "";
 
  // build the full request body
  req.addListener("body", function(chunk) {
        body+=chunk;
  });
 
  req.addListener("complete", function() {
       // body is the full request body
  });


Hope it helps!

-- Elijah


--

You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.



Jason Wang

unread,
Dec 28, 2009, 5:32:16 PM12/28/09
to nodejs
Well, it turned out my code works (thank you Elljah for confirming
that the problem is somewhere else!). I didn't get anything is because
i did not put a name attribute to my form elements. Stupid me, thanks
a lot!

Jason

> > nodejs+un...@googlegroups.com<nodejs%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages