Processing ajax form

I’m learning rails, while doing my app.
So this is just the tip of the ice berg and I foresee many more
questions
in future.

I have the following setup.
Basically, on clicking the login button, a ajax request is sent, and the
json response “message”:“fail” is returned.

My question is, how do I get the response in the success callback for
processing?
Here’s what I have at the moment.

index.html.erb

Log in

<%= form_for @user, :remote => true, :url => { :action => "login", :controller => "users" }, :html => { :class => "login" } do |f| %> <%= label_tag(:password, "Password") %> <%= f.text_field :password %> <%= f.submit "Login" %> <% end %>

home.js.coffee

$ ->
$(‘form’).bind ‘ajax:success’, (result) -> console.log(result)

Output of console log

jQuery.Event {type: “ajax:success”, timeStamp: 1353575112551,
jQuery18209272595844231546: true, isTrigger: true, exclusive: undefined}

I was actually expecting the console log output to be something like
result[{
“message” : “fail”}]?

Well, found my answer:

$ →
$(‘form’).bind ‘ajax:success’, (event,data,status,xhr) →
console.log(data)

source:

On Thursday, 22 November 2012 17:21:12 UTC+8, resting wrote:

I’m learning rails, while doing my app.