2011-01-21 64 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

相關問題