Bootstrap modal dialog box to load only one remote data solution

Source: Internet
Author: User

The Bootstrap modal dialog box for the front-end frame allows you to specify a URL using the remote option so that the dialog box will automatically load data from this address at the first pop-up to. Modal-body, but it will only be loaded once, but by invoking the The Removedata () method can solve this problem.

Bootstrap modals Dialog Hidden Removedata

Catalogue [-]

    • 1. Bootstrap modal dialog box and simple use
    • 2. Use the remote option to have the modal dialog box load the page into the. modal-body
    • 2.1 Using Links
    • 2.2 Using scripts
    • 3. Remove the data so that the dialog box can reload the page each time it is opened
    • Reference documents
1. Bootstrap modal dialog box and simple use
12345678910111213 <divid="myModal"class="modal hide fade">    <divclass="modal-header">        <buttontype="button"class="close"data-dismiss="modal">x</button>        <h3>对话框标题</h3>    </div>    <divclass="modal-body">        <p>对话框主体</p>    </div>    <divclass="modal-footer">        <ahref="#" class="btn"data-dismiss="modal">取消</a>        <ahref="#"class="btn btn-primary"data-dismiss="modal">确定</a>    </div></div>

Display effects similar to:

Modal dialogs can be called directly using buttons or links, which is simple to use:

12 <buttontype="button"data-toggle="modal"data-target="#myModal">打开对话框</button><ahref="#myModal"role="button"class="btn"data-toggle="modal">打开对话框</button>

This will only show the static content in the dialog box, using the Remote option of the dialog box to achieve a more powerful effect.

2. Use the remote option to have the modal dialog box load the page into the. modal-body

There are two ways to use a link, and the other is to use a script.

2.1 Using Links
1 <ahref="page.jsp" data-toggle="modal"data-target="#myModal">打开对话框</a>

When this link is clicked, the contents of the page.jsp will be loaded into the. Modal-body dialog box.

2.2 Using scripts
123 $("#myModal").modal({    remote: "page.jsp"});

The effect of this script is the same as using a link, and when the script executes, the contents of the page.jsp are loaded into the. Modal-body of the dialog box, and the dialog box appears.

Behind both methods, Bootstrap called the JQuery Load () method and loaded the page.jsp page from the server side. But this load will only happen once, no matter how many times you click the link, or execute a few scripts, even if you change the value passed to the Remote option, the dialog box will not reload the page, this is a very frustrating thing. But the problem can still be solved.

3. Remove the data so that the dialog box can reload the page each time it is opened

After searching and reviewing the relevant documents, it is possible to write a statement in the hidden event of the dialog box:

123 $("#myModal").on("hidden"function() {    $(this).removeData("modal");});

You can also remove the data before you open the dialog box, the effect is the same.

Note: The above code is based on Bootstrap v2, if you use Bootstrape v3, the modal dialog's HTML and event notation are somewhat different, for example, for the above hidden event, write:

123 $("#myModal").on("hidden.bs.modal"function() {    $(this).removeData("bs.modal");});
Http://my.oschina.net/qczhang/blog/190215?p=1

Bootstrap modal dialog box to load only one remote data solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.