从JavaScript在rails3执行控制器/动作 [英] execute controller/action from javascript in rails3

查看:85
本文介绍了从JavaScript在rails3执行控制器/动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在_new.html.erb一个下面的函数。我想调用一个控制器时,element_id_placeholder改变:

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_placeholder").observe_field(1, function( ) {                                       
        alert('Change observed! new value: ' + this.value );
        // call controller 

      });
    });

  </script>

我使用的是轨道3

I'm using rails 3

推荐答案

使用jQuery的AJAX方法:

Use jQuery's ajax method:

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

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

这篇关于从JavaScript在rails3执行控制器/动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆