提交后如何使Facebox弹出窗口保持打开状态并且Facebox中的内容发生更改 [英] How to make facebox popup remain open and the content inside the facebox changes after the submit

查看:97
本文介绍了提交后如何使Facebox弹出窗口保持打开状态并且Facebox中的内容发生更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是jQuery总 n00b . 在我的Rails应用程序中会发生以下情况:

I'm a jQuery total n00b. In my rails app this what happen:

我在主页上,单击此链接:

I'm on the homepage, I click this link:

<a href='/betas/new' rel='facebox'>Sign up</a>

出现一个漂亮的Facebox弹出窗口,并呈现此视图和包含的表单:

A beautiful facebox popup shows up and render this views and the containing form:

# /app/views/invites/new

<% form_tag({ :controller => 'registration_code', :action => 'create' }, :id => 'codeForm') do %>

    <%= text_field_tag :code %>
    <br />
    <%= submit_tag 'Confirm' %>
<% end %>

我在提交时碰了一下,如果代码有效,则将用户带到另一个控制器的另一个页面上

I clink on submit and if the code is valid the user is taken on another page in another controller:

def create
  # some stuff
  redirect_to :controller => 'users', :action => 'type'
end

现在,我想在提交"按钮被按下后,在相同"弹出窗口内显示该页面,但是我不知道该怎么做.我已经尝试过 FaceboxRender ,但这会发生:

Now I would like to render that page INSIDE the SAME popup contains the form, after the submit button is pressed but I have NO IDEA how to do it. I've tried FaceboxRender but this happens:

原始版本:

# /controllers/users_controller
def type
end

如果我这样更改它,则什么也不会发生:

If I change it like that nothing happens:

# /controllers/users_controller
def type
  respond_to do |format|
  format.html
  format.js { render_to_facebox }
 end
end

如果我这样更改它(我知道是错的,但是我是n00b,这样就可以了:-):

If I change it like that (I know is wrong but I'm a n00b so it's ok :-):

# /controllers/users_controller
def type
  respond_to do |format|
  format.html { render_to_facebox }
  format.js
 end
end

我得到了这个渲染图:

try {
jQuery.facebox("my raw HTML from users/type.html.erb substituted here")'); throw e }

有解决方案吗?

非常感谢!

现在我得到一个 Firebug控制台出现未定义Ajax"错误.是什么意思?

Now I get an "Ajax not defined" error from the firebug console. What does it means?

推荐答案

您可以继续使用facebox_render或其中的一个fork,这将使一切变得简单:)

You can continue using facebox_render or one of it's forks, it will make everything a bit easier :)

关于您的问题,您需要的是面板内的表单以发出AJAX请求,因此您可以使用format.js响应此调用.因此,在这种情况下,您需要form_remote_tag才能使用AJAX发布数据.

About your problem, what you need is the form inside the facebox to make an AJAX request so you can use format.js to repond to this call. So, in this case, you need form_remote_tag to post your data using AJAX.

在控制器中,您将收到一个AJAX请求,将使用response_to.js处理该请求,然后可以再次创建render_to_facebox.现在,您将在面板中看到所需的内容.

In the controller you will receive an AJAX request, you'll handle it with respond_to.js and then you can make a render_to_facebox again. Now you will see what you want inside of the facebox.

在视图中:

# /app/views/invites/new
<% form_remote_tag({ :controller => 'registration_code', :action => 'create' }, :id => 'codeForm') do %>

    <%= text_field_tag :code %>
    <br />
    <%= submit_tag 'Confirm' %>
<% end %>

在控制器中:

# /controllers/users_controller
def type
  respond_to do |format|
    format.html
    format.js { render_to_facebox }
  end
end

希望对您有所帮助!

这篇关于提交后如何使Facebox弹出窗口保持打开状态并且Facebox中的内容发生更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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