【问题标题】:rails ajax update only oncerails ajax 只更新一次
【发布时间】:2009-08-22 22:26:15
【问题描述】:

我有一个 remote_form_for 用于让用户知道他们的表单是否已成功提交。在这种方法中我有:success=>'updateMain()

我想向 updateMain 添加一个 ajax 更新请求。问题是我找不到在 Rails 中发出单个更新请求的方法(我知道这在原型中可用)。

我发现的最接近的东西是periodic_call_remote,但这不是我想要的,因为它会继续轮询服务器(我只需要它发生一次)

另一个问题是ajax代码需要进入updateMain js方法,所以我不能使用periodic_call_remote,因为它会自动用<script></script>包装它的js代码。

我可以使用原型手动编写此代码,但使用 rails 会很好。有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails ajax prototype


    【解决方案1】:

    在你的 remote_form_for 提交的控制器方法中,你为什么不直接使用 render :update?

    def ajax_method
        # If the form was valid
        render :update do |page|
            page.replace_html 'id_of_div_to_update', :partial => 'successful_form_submission'
        end
    end
    

    每次提交 ajax 表单时页面都会更新。

    【讨论】:

      猜你喜欢
      • 2012-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-20
      • 2020-10-30
      相关资源
      最近更新 更多