Twitter Bootstrap 模态提交按钮,用于在 Rails 中提交和打开模态 [英] Twitter Bootstrap Modal submit button to submit and open modal in Rails
本文介绍了Twitter Bootstrap 模态提交按钮,用于在 Rails 中提交和打开模态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 Twitter Bootstrap 模态按钮 (haml) - 我想用这个按钮来保存我的表单,然后打开模态对话框询问我是否要打印它.我怎样才能让这个按钮执行提交或保存:
I have the following Twitter Bootstrap Modal button (haml) - I want to use this button to save my form then open the modal dialog to ask if I want to print it. How Can I make this button perform a submit or save :
%a.btn{"data-toggle" => "modal", :href => "#myModal",
class: 'btn btn-inverse btn-large',
:role => "button"} Press to Complete Visit
#myModal.modal.hide.fade{"aria-hidden" => "true",
"aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
推荐答案
你应该做一个 AJAX 帖子并有一个端点来接收数据.
You should do an AJAX post and have an endpoint to receive the data.
HTML:
%a.btn{class: 'btn btn-inverse btn-large',
id: 'submit-btn',
:role => "button"} Press to Complete Visit
#myModal.modal.hide.fade{"aria-hidden" => "true",
"aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
Javascript:
Javascript:
$('#submit-btn').click(function() {
$.ajax({
type: post,
url: '/your-end-point',
data: your_data,
success: function() {
$('#myModal').show();
}
})
})
导轨:
routes.rb
post 'your_end_point' => 'your_controller#submit'
your_controller.rb
def submit
# Save form data...
render :json => 'success'
end
这篇关于Twitter Bootstrap 模态提交按钮,用于在 Rails 中提交和打开模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文