blundin
blundin

Reputation: 1643

Multiple AJAX requests from one button in Rails 3.2

I want to create one button (preferably using 'button_to') in a Rails 3.2 app that sends three separate AJAX requests to different actions of the same controller.

I have not seen anything online showing how I could do this. Is it possible?

Upvotes: 0

Views: 525

Answers (1)

Mark Stratmann
Mark Stratmann

Reputation: 1612

You will need to get some javascript in your page like the example below

Check out http://api.jquery.com/jQuery.get/

 // Deal with any button clicks
  $(document).on("click", "#mybuttonid", function(event) {
     $.get('ajax/firsttest.html', function(data) {
      $('.result').html(data);
      alert('First Load was performed.');
                                             });
     $.get('ajax/secondtest.html', function(data) {
      $('.result').html(data);
      alert(' Second Load was performed.');
                                             });

     $.get('ajax/thirdtest.html', function(data) {
      $('.result').html(data);
      alert('Third Load was performed.');
                                             });

})

Upvotes: 1

Related Questions