jQuery 将数据发布到新的弹出窗口而不使用隐藏的输入字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3200357/
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-08-26 15:00:41  来源:igfitidea点击:

Post data to a new popup window without using hidden input fields

jqueryajaxpopup

提问by bcm

Is it possible to post data to a new window without using hidden input fields. Data can be possibly quite large. Looking at something similar to jQuery ajax type post.. except I need to post the data to a new page.

是否可以在不使用隐藏输入字段的情况下将数据发布到新窗口。数据可能非常大。查看类似于 jQuery ajax 类型 post.. 的内容,但我需要将数据发布到新页面。

回答by TNi

A hidden form is the standard approach to this. I don't recall if the following has complications, but you may even be able to create the form on the fly and submit it. In my opinion, there's nothing wrong with this approach. Another possibility is to use jQuery.post()and in the callback function open a new window and paste the returned content. For example,

隐藏表单是解决此问题的标准方法。我不记得以下是否有并发症,但您甚至可以即时创建表单并提交。在我看来,这种方法没有任何问题。另一种可能性是使用jQuery.post()并在回调函数中打开一个新窗口并粘贴返回的内容。例如,

var win = window.open();
win.document.write(returnedContent);

回答by bcm

eureka! this test works:

尤里卡!这个测试有效:

function postData() {           
        $.post('popup.aspx', { text1: "aaa", text2: "bbb" }, function (result) {
            WinId = window.open('', 'newwin', 'width=400,height=500');
            WinId.document.open();
            WinId.document.write(result);
            WinId.document.close();
        });
    }

on popup.aspx.cs

在 popup.aspx.cs 上

test1.Text = Request["text1"];
test2.Text = Request["text2"];

on popup.aspx

在 popup.aspx 上

<asp:Label ID= "test1" runat="server"></asp:Label>
<asp:Label ID= "test2" runat="server"></asp:Label>