Well, found my answer:
$ ->
$(''form'').bind ''ajax:success'',
(event,data,status,xhr) -> console.log(data)
source:
http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/
On Thursday, 22 November 2012 17:21:12 UTC+8, resting wrote:
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
>
> <h2>Log in</h2>
> <%= 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"}]?
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/T0kuS12ur-gJ.
For more options, visit https://groups.google.com/groups/opt_out.