Calling an action within javascript function w/ ajax

I am trying to call an action within a javscript function using ajax,
but I am having some problems. I need the ajax call to return a value
and am thinking I can do this using onComplete and Ajax.Request but I
am running into some problems. This is the code I am using for the

new Ajax.Request( '/users/username', {
  method: 'post',
  parameters: { username: $('new_user_username').value},
  onComplete: parseResults()

I have an action called username in my users controller in which I am
taking the username params passed by the Ajax.Request and seeing if it
exists in the database. I want to return true/false depending on if
it exists or not. But I am having trouble even getting the
Ajax.Request to work.

This is some of the output from the console:

Processing UsersController#username (for at 2008-12-13
19:52:39) [POST]
Session ID:
Parameters: {“username”=>“d”, “action”=>“username”,


Im not sure how to get around this InvalidAuthenticityToken, anyone
have any idea whats going on here. Ive been struggling with this for
a while and am somewhat new to ajax so I could use some help.

Im thinking this needs to be a ‘GET’ request in order to return a
response, but when I change the method to a GET, it calls the show

Parameters: {“username”=>“f”, “action”=>“show”, “id”=>“username”,


Just use remote_function and it will generate the appropriate ajax
call for you - this will make your code much less brittle to Rails