2012-11-21 52 views
5

我试图加载“远程”内容,基本上是通过HTTP请求(在同一站点上)发送的信息。返回的内容本身抛出回的信息,如:Twitter Bootstrap模式 - 加载“远程”内容

<div class="modal-header"> 
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times; </button> 
<h3>Change Your Password</h3> 
</div> 
<div class="modal-body"> 
<form> 
    <fieldset> 
     <label>Your current password</label> 
     <input type="password" placeholder="password"> 
     <label>Confirm current password</label> 
     <input type="text" placeholder="password"> 

     <button type="submit" class="btn">Submit</button> 
    </fieldset> 
</form> 
</div> 
<div class="modal-footer"> 
    <a href="#" class="btn btn-primary" data-dismiss="modal">Close</a> 
</div> 

然而,对于模式对话框,显示远程内容,我认为我应该显示已经modal-body类:

<div class="modal fade hide" id="ajax"> 
    <div class="modal-body"> 
     <p>body content to be replaced</p> 
    </div> 
</div> 

怎么办我绕过这一步,并提供完整的模态div内容,并使其正确显示?

回答

3

看起来你想用网页填充模态体。你可以使用a标签和使用数据对象调用模式属性:

<a id="file_attach" data-toggle="modal" href="http://fiddle.jshell.net/jhfrench/6K8rD/show/" data-target="#utility" class="btn">Modal 1</a>

Twitter documentation笔记

如果提供了一个远程URL,内容将通过jQuery的负载 加载方法并注入模体。如果您使用的数据为 api,则可以使用href标签指定远程源 。

http://jsfiddle.net/jhfrench/qv5u5/为例(看How can I reuse one Bootstrap modal div?关于如何resuse多个调用链接之间的一个模式的细节)。

+2

请注意,通过AJAX将页面加载到模式中,因此受到“相同原点策略”限制(即:您将无法将awesomesite.com加载到托管在myapp.com上的div中) 。 –

+0

是否意味着通过href返回的响应应该是AJAX响应?或者我们可以从同一个应用程序获得一些其他页面。 – Mutant

+0

@mutant:对不起,我不认为我理解你的问题。 –

相关问题