When using jQuery, I typically implement the following approach:
First, select the element you want to trigger an event on, such as clicking:
$(function() {
$('#foo').click( function(){
var params = '{"field1": "value1", "field2: "value2"}';
$.get('/controller/bar', params, function(data){
alert(data);
});
});
});
Next, in your Rails controller:
def bar
/// perform necessary operations
render :json => {"response" => "OK"}
end
Ensure you have the corresponding route set up in your routes.rb file:
match 'controller/bar' => 'controller#bar'
Lastly, customize the word "controller" according to your specific code. Remember that tools like Firebug can help troubleshoot any issues!