2011-01-21 67 views
2

我的_new.html.erb中有以下功能。我想打电话给控制器时element_id_placeholder改变:从rails中执行控制器/动作3

<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> 

我使用的是轨道3

回答

5

使用jQuery的Ajax方法:

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

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

+0

感谢那些作品,但它转到我的控制器/视图。我怎么会调用一些方法来返回模型对象,甚至是我可以作为该方法的一部分构建的json对象? – user140736 2011-01-21 02:15:26

相关问题