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
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
Here’s what I have at the moment.


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 %>

$ ->
$(‘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
“message” : “fail”}]?

Well, found my answer:

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


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

I’m learning rails, while doing my app.