javascript 如何使用 jQuery 将 jsp 页面中的内容加载到模态窗口中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19113900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 14:24:55  来源:igfitidea点击:

How do I load the content from a jsp page into a modal window using jQuery?

javascriptjqueryjspjquery-ui-dialog

提问by Ray

I am trying to find the best implementation for this situation. I want load the content from a jsp page to a popup window, I tried to use SimpleModal but this library doesn't work with a jsp page, now I'm trying to use a Dialog from JQuery UI. However, this also doesn't work.

我正在尝试为这种情况找到最佳实现。我想将内容从 jsp 页面加载到弹出窗口,我尝试使用 SimpleModal 但该库不适用于 jsp 页面,现在我正在尝试使用 JQuery UI 中的对话框。但是,这也不起作用。

Here is my code below:

这是我的代码如下:

function loadPage() {    
    $("#loaderPage").load("test1.jsp");
    $("#loaderPage").dialog({
        height: 600, 
        width: 600, 
        modal: true
    }); 
    return false;
}

I'm not getting an error, but I'm also not getting a dialog to popup. What can be wrong and how I can resolve my problem?

我没有收到错误消息,但也没有弹出对话框。有什么问题以及如何解决我的问题?

采纳答案by stepanian

JSP pages send regular HTML to the browser, so it doesn't matter if it is a JSP page or any other kind of server side technology that is generating the page that you are calling.

JSP 页面将常规 HTML 发送到浏览器,因此它是 JSP 页面还是生成您正在调用的页面的任何其他类型的服务器端技术都没有关系。

Make sure that the relative path to the "test.jsp" page is the same as the the page where the script is included.

确保“test.jsp”页面的相对路径与包含脚本的页面相同。

Also make sure that there is an element, such as a div, that has an id attribute that is equal to "loaderPage".

还要确保有一个元素,例如 div,其 id 属性等于“loaderPage”。

Make sure you include the jquery and jquery-ui libraries as Arun Killu mentioned in his comment.

确保包含了 Arun Killu 在他的评论中提到的 jquery 和 jquery-ui 库。

Also, it may make sense to use an iframe. See this:

此外,使用 iframe 可能是有意义的。看到这个:

How to dynamically load content from an external url, inside of a jquery ui modal dialog widget?

如何在 jquery ui 模态对话框小部件内从外部 url 动态加载内容?