开发者

execute controller/action from javascript in rails3

开发者 https://www.devze.com 2023-02-05 16:28 出处:网络
I have a following function in my _new.html.erb. I would like to call a controller when the element_id_placeholder is changed:

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消