无法在ajax请求后显示twitter bootstrap模式

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

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

主页

 'btn primary float-right bootstrap-popover' %>  

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(" 'new_form')%>"); $('#modal_form').modal('show'); 

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

有人可以帮忙吗?

是因为加载元素没有被隐藏?

 $('loading').hide(); 

这不应该是这样的:

 $('#loading').hide(); 

我认为在你的ajax请求获得成功之后你必须写下面代码之类的内容。

 $('#PopupBoxId').modal('show'); // Show the pop-up (modal) $('#disable_layer').modal('show'); // Show the black overlay 

我们必须在ajax请求处理后手动显示弹出窗口。根据我在bootstrap中的小经验。 🙂

希望对你有效。

你有没有看过Bootstrap模态管理器 ? 您可以像这样使用它:

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

您可以在Bootstrap Modal Manager的实时演示页面上看到这一点(向下滚动一下,查找AJAX演示)。