Hi, I'd like to know how can I do a button that on click with call an
action, but wont reload the page.

Like the "like" button at facebook.

Thanks in advance.

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Robert Walker at Mar 2, 2012 at 10:08 pm

    Rodrigo Ruiz wrote in post #1049716:
    Hi, I'd like to know how can I do a button that on click with call an
    action, but wont reload the page.
    If you're calling back to your same origin (domain) then you can use
    XHTTPRequest (a.k.a. AJAX). We almost never use that object directly.
    It's usually managed by a JavaScript framework such as jQuery.

    Example:
    ------------------
    $(function() {
    $('my_button').click(clickHandler);
    });

    function clickHandler() {
    $('target_div').load('http://example.com/posts');
    }

    This would first wait for the DOM to load (to make sure the button
    element is available), then bind a click event to the button element.

    Clicking the button calls the handler function, which then uses jQuery
    to send a request to a URL that returns an HTML fragment, which finally
    gets loaded inside of the target_div.
    Like the "like" button at facebook.
    I'm guessing the Facebook Like button has to do some fairly tricky
    things to get around the "same origin" policy. It doesn't sound like
    that's really what you need.

    --
    Posted via http://www.ruby-forum.com/.

    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 1, '12 at 9:37p
activeMar 2, '12 at 10:08p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Rodrigo Ruiz: 1 post Robert Walker: 1 post

People

Translate

site design / logo © 2022 Grokbase