从rails3中的javascript执行控制器/动作

use*_*736 2 javascript ajax ruby-on-rails ruby-on-rails-3

我的_new.html.erb中有以下功能.我想在更改element_id_placeholder时调用控制器:

 <script type="text/javascript">

    // When DOM loads, init the page.
    $(function() {
      // Executes a callback detecting changes with a frequency of 1 second
      $("#id_element_placeholder").observe_field(1, function( ) {                                       
        alert('Change observed! new value: ' + this.value );
        // call controller 

      });
    });

  </script>
Run Code Online (Sandbox Code Playgroud)

我正在使用rails 3

apn*_*ing 5

使用jQuery的ajax方法:

$.ajax({
type: "GET",
url: "/articles/" + $(this).attr('value'),
success: function(data){}
});
Run Code Online (Sandbox Code Playgroud)

http://api.jquery.com/jQuery.ajax/