如何使facebox弹出窗口保持打开状态并且提交后facebox内的内容发生变化
我是 jQuery 总 n00b。 在我的 Rails 应用程序中,发生了什么:
我在主页上,单击此链接:
<a href='/betas/new' rel='facebox'>Sign up</a>
出现一个漂亮的 Facebox 弹出窗口并呈现此视图和包含的表单:
# /app/views/invites/new
<% form_tag({ :controller => 'registration_code', :action => 'create' }, :id => 'codeForm') do %>
<%= text_field_tag :code %>
<br />
<%= submit_tag 'Confirm' %>
<% end %>
我点击提交,如果代码有效,则用户将被接受另一个控制器中的另一个页面:
def create
# some stuff
redirect_to :controller => 'users', :action => 'type'
end
现在我想在按下提交按钮后在包含表单的同一弹出窗口内渲染该页面,但我不知道如何做到这一点。我尝试过 FaceboxRender 但发生这种情况:
原始版本:
# /controllers/users_controller
def type
end
如果我像这样更改它,则不会发生:
# /controllers/users_controller
def type
respond_to do |format|
format.html
format.js { render_to_facebox }
end
end
如果我这样改变它(我知道这是错误的,但我是一个n00b,所以没关系:-):
# /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 未定义”错误。这意味着什么?
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>
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
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:
Original version:
# /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
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
I got this rendered:
try {
jQuery.facebox("my raw HTML from users/type.html.erb substituted here")'); throw e }
Any solutions?
THANK YOU SO MUCH!!
Now I get an
"Ajax not defined" error from the firebug console. What does it means?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以继续使用facebox_render或其分支之一,它会让一切变得更容易:)
关于您的问题,您需要的是facebox内的表单来发出AJAX请求,以便您可以使用format.js来响应此调用。因此,在这种情况下,您需要
form_remote_tag
使用 AJAX 发布数据。在控制器中,您将收到一个 AJAX 请求,您将使用 respond_to.js 处理它,然后您可以再次创建 render_to_facebox。现在您将在脸盒中看到您想要的内容。
在视图中:
在控制器中:
我希望它能有所帮助,ciao!
You can continue using facebox_render or one of it's forks, it will make everything a bit easier :)
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.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.
In the view:
And in the controller:
I hope it helps a bit, ciao!