ajax请求后无法显示twitter引导模式

ajax请求后无法显示twitter引导模式

本文介绍了ajax请求后无法显示twitter引导模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在点击链接时显示模态窗口,但也想做 ajax 请求以获取需要在模态窗口上显示的对象.

I want to show modal window on click of link but also want to do ajax request to get the object which needs to be shown on modal window.

我收到了需要在模态窗口上显示的内容的响应,但它没有作为模态窗口弹出,可能是脚本没有被执行.

I am getting response with the content which needs to be shown on modal window but it is not popping up as modal window probably the script is not getting executed.

代码

主页

  <%= link_to "New Topic", "#", :class => 'btn primary float-right bootstrap-popover'   %>
  <div id="modal_form_container"></div>

Javascript 代码

   $('a.bootstrap-popover').live('click',  function(){
   $(this).unbind('click');

   $.ajax({
          url: "/topics/new",
          type: "GET",
          dataType: "html",


          complete: function() {
            $('loading').hide();
          },

     success: function(data) {

     },

     error:function() {
        }
      }); // End of Ajax

new.js.erb

$('#modal_form_container').html("<%= escape_javascript( render :partial => 'new_form')%>");
$('#modal_form').modal('show');

这个 new_form 页面包含要在模态窗口中显示的内容

This new_form page contains content to be shown on modal window

有人可以帮忙吗?

推荐答案

你有没有研究过 Bootstrap Modal Manager?你可以这样使用它:

Have you looked into the Bootstrap Modal Manager? You can use it like so:

$("a.open-with-ajax-loader").live('click', function(e){
  e.preventDefault();
  $('body').modalmanager('loading');
  $('#id-of-modal-div').modal({
    remote: '/url/to/load'
  });
});

您可以在 Bootstrap 模态管理器的现场演示页面上看到这一点(向下滚动一点,寻找 AJAX 演示).

You can see this in action on the live demo page for the Bootstrap Modal Manager ( scroll down a bit, look for the AJAX demo ).

这篇关于ajax请求后无法显示twitter引导模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 00:54