【问题标题】:How to render server response as HTML into a popup window? jQuery如何将服务器响应作为 HTML 呈现到弹出窗口中? jQuery
【发布时间】:2013-12-03 19:44:10
【问题描述】:

所以我从服务器收到一封电子邮件的 HTML 响应,在 jQuery 中我试图将该响应呈现到一个弹出窗口中。

我一开始试过这个:

postToServerWithAjax('/invite_preview', null, function (response) {
    window.open($(response), "popupWindow", "width=600,height=600,scrollbars=yes");
});



然而,这只是在 URL 中打开了带有 [object, object] 的弹出窗口。我在下面尝试了 .html()

postToServerWithAjax('/invite_preview', null, function (response) {
    window.open($(response).html(), "popupWindow", "width=600,height=600,scrollbars=yes");
});

^ 这只是返回一个空白的弹出窗口


然后我只尝试了一个空白页面,但我的代码不断将 HTML 放入 url 栏中:

window.open(response).html();



在将 HTML 实际呈现到新的弹出窗口/页面中时,我缺少什么?


在这里找到了一些示例,并使用了答案,但还没有得到要呈现的 HTML :(

display html code of response returned by ajax, Jquery

jQuery function to open link in new window

【问题讨论】:

    标签: javascript jquery html response


    【解决方案1】:

    第一个参数是一个URL,不是实际内容,你必须把它写到窗口

    postToServerWithAjax('/invite_preview', null, function (response) {
       var wind = window.open("", "popupWindow", "width=600,height=600,scrollbars=yes");
       wind.document.write(response);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-26
      • 1970-01-01
      • 1970-01-01
      • 2015-07-10
      • 2018-10-28
      • 1970-01-01
      相关资源
      最近更新 更多