2013-10-18 18 views
0

我有一个页面调用具有外部内容的引导程序模式窗口。模态窗口由一个表单组成。表单使用jquery验证,我试图使用ajax提交处理程序。问题是,它似乎并不能访问我想要更新的主要div。模态窗口使用自己的html页面。我想更新一个用来调用模态窗口的div,是这样的吗?如何在引导程序模式外更新div

没有代码,除非你想让我发布以更好地阐明。希望我想做的事情是有道理的。

编辑:主页是我想从Ajax调用的模式更新的内容]

[Main Page] 
<div id='div-id-want-to-update-on-submit'></div> 

<a href='/some-external-form' data-toggle='modal' data-target='#my-modal'>Launch Modal</a> 

[Modal Window] 
<div id="my-modal" class="modal hide fade"> 
    <div class="modal-header"> 
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
    <h3 id="myModalLabel">Modal header</h3> 
    </div> 
    <div class="modal-body"> 
    <form action=/post-somewhere> 
... 
    </form> 
    </div> 
    <div class="modal-footer"> 
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> 
    <button class="btn btn-primary">Save changes</button> 
    </div> 
</div> 

<script type="text/javascript"> 
... some jquery to validate and ajax call to another method. 

    var request; 
    request = $.ajax({ 
     url: '/post-method/returns-html', 
     type: "post", 
     data: serializedData 
    }); 

    request.done(function (response, textStatus, jqXHR) { 
     $('#div-id-want-to-update-on-submit').html(response); 
    }); 
</script> 

[EDIT2] - 忽略这一点,我做我的更新DIV一个愚蠢的类型。如下所示,不需要window.opener,DOM可从主页面获得。

+2

是的,你最好向我们展示你的代码。 – 2013-10-18 14:22:02

回答

0

你应该能够window.opener.document

例如引用开放文档

request.done(function (response, textStatus, jqXHR) { 
    $(window.opener.document).find('#div-id-want-to-update-on-submit').html(response); 
}); 
+0

这是抛出一个异常:未捕获TypeError:无法读取null的属性'文档' – Jeff

+0

您是在服务器上测试它,还是只是通过file://在同一个域上是外部窗体? – spacebean

+0

全部包含在同一台服务器上。 – Jeff