execute controller/action from javascript in rails3
I have a following function in my _new.html.erb. I would like to call a controller when the element_id_placeholder is changed:
<script type="text/javascript">
// When DOM loads, init the page.
$(function() {
// Executes a callback detecting changes with a frequency of 1 second
$("#id_element_pl开发者_JAVA技巧aceholder").observe_field(1, function( ) {
alert('Change observed! new value: ' + this.value );
// call controller
});
});
</script>
I'm using rails 3
Use jQuery's ajax method:
$.ajax({
type: "GET",
url: "/articles/" + $(this).attr('value'),
success: function(data){}
});
http://api.jquery.com/jQuery.ajax/
精彩评论