如何使用Rails 3实现jQuery Ajax成功方法的部分渲染 [英] How to do render partial on jQuery ajax success method with rails 3

查看:86
本文介绍了如何使用Rails 3实现jQuery Ajax成功方法的部分渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 3.2.1和jQuery进行ajax调用.

I'm using rails 3.2.1 with jQuery for an ajax call.

我的jQuery代码是:

My jQuery code is :

jQuery.ajax({
  url: "/org_pages",
  data: 'org_id='+ org_id,
  type: "POST",
  success: function(result){                        
    jQuery("#image_center").html("<%= escape_javascript(render(:partial => 'pages/top_link')) %>");
  },
  error: function(){
    alert('Error occured');
  }
});

我的问题是网页上的输出显示如下:

My problem is on the web page the output is showing this :

<%= render :partial => 'pages/top_link', :collection=>@pages %>

它应如何显示我的渲染部分页面. :(

How it should display my render partial page. :(

推荐答案

尝试通过将控制器的部分呈现为

try by rendering the partial from the controller as,

def method_name
  render :partial => 'some_partial'
end

和js

success: function(result){                      
  jQuery("#image_center").html(result);
}

否则

创建与该操作相对应的js.erb文件,并在其中粘贴以下内容:

create a js.erb file corresponding to that action and inside that paste the following:

jQuery("#image_center").html("<%= escape_javascript(render(:partial => 'pages/top_link')) %>");

这篇关于如何使用Rails 3实现jQuery Ajax成功方法的部分渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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