2013-10-18 20 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