如何在引导模态之外更新div [英] How to update div outside bootstrap modal

查看:58
本文介绍了如何在引导模态之外更新div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,该页面调用带有外部内容的引导模式窗口.模态窗口由一个表单组成.该表单正在使用jquery validate,并且我正在尝试使用ajax提交处理程序.问题在于,似乎我无法访问要更新的主div.模态窗口正在使用其自己的html页面.我想更新用于调用模式窗口的div,是否可能这样?

I have a page that calls a bootstrap modal window with external content. The modal window consists of a form. The form is using jquery validate and I'm trying to use an ajax submit handler. The problem is that it doesn't seem I can access the main div I want to update from. The modal window is using its own html page. I want to update a div that was used to call the modal window, is something like this possible?

没有代码,除非您希望我发布以进一步阐明.希望我想做的有意义.

No code unless you want me to post to better clarify. Hope what I want to do makes sense.

[主页是我想从模式下的ajax调用中更新的内容]

edit: [Main page is what I want to update from ajax call in modal]

[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.

[edit2] - Ignore this, I made a stupid type in my update div. no window.opener was needed as recommended below, the DOM is available from the main page.

推荐答案

您应该可以使用window.opener.document

例如

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

这篇关于如何在引导模态之外更新div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆