Reputation: 1643
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
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