刷新部分(Rails的阿贾克斯) [英] Reload Partial (Rails Ajax)

查看:108
本文介绍了刷新部分(Rails的阿贾克斯)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,当我点击提交,应该更新的部分是在同一页上... 当我在这里把这样的:

I have a form that when I click submit, should update a partial that is on the same page... When I place this here:

page.replace_html 'show_cards_div', 'Hello'

这不只是因为它应该显示Hello,当我需要它。但是,当我把它变成这个......

It does just as it should, display hello when I need it to. But when I make it into this....

page.replace_html 'show_cards_div', :partial => "reloadThisPartial"`

它根本没有做任何事情。我究竟做错了什么?

It simply does not do anything. What am I doing wrong?

推荐答案

请求可能不是一个Ajax调用。使Ajax调用。用户remote_form_for代替的form_for或使用jquery.form发送Ajax调用到控制器。如果你正在使用jQuery的话做这样的事情:

The request might not be an Ajax call. Make Ajax call. User remote_form_for instead of form_for or use jquery.form for sending ajax calls to controller. If you are using jquery then do something like:

<%= javascript_include_tag "jquery-1.4.4.min.js", "jquery.form" %>
<%= form_for :user, :url => {:controller =>  "come_controller",:action => "some_action"}, :html => {:id => 'form_id', :class => 'cmxform', :onsubmit => "return false;"} do |f| %>
......................................
<% end %>

<script type="text/javascript">
$('#form_id').submit(function() {
var container = $("#show_cards_div");
            $(this).unbind('submit').ajaxSubmit({
              success: function(data) {
                     container.html(data);
              }
            })
            return false
          });
</script>

在控制器做这样的事情。

in controller do something like this.

render :partial => "reloadThisPartial", :layout => false, :locals =>{:users =>@users}

这篇关于刷新部分(Rails的阿贾克斯)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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