显示包含动态加载的HTML内容的对话框

时间:2011-08-16 20:20:20

标签: jquery asp.net-mvc-3 jquery-ui dialog

我想显示一个包含动态生成的HTML的对话框:

 $.ajax({
        type: "get",
        url: "http://localhost/example/test",
        dataType: "html",
        success: function (content) {
            $(content).dialog();
        }
    });

content基本上是一个包含标题和正文的完整HTML网站。如果我将$(content).dialog()更改为alert(content),则会正确显示生成的HTML。但content.dialog()在Firefox 5上抛出以下异常:

a.style is undefined 
Source: http://localhost/TrackerWebStable/Scripts/jquery-1.4.4.min.js
Line: 150

我也用IE8测试了它,我得到了类似的错误。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

content将包含整个html标记。我相信你想在对话框中展示它的一部分。尝试从整个html中找到所需的元素并在对话框中显示它。

或者,您只能从"http://localhost/example/test发送所需的标记,这样您就不必在成功处理程序中找到任何内容,只需在对话框中显示它。

$.ajax({
        type: "get",
        url: "http://localhost/example/test",
        dataType: "html",
        success: function (content) {
            $(content).find("requiredElement").dialog();
        }
    });