0

我想使用 POST 将数据从页面传递到另一个页面,并在我的第二页上显示名字和姓氏。但它确实显示了实际代码,而不是名称。请看下面的代码:

<html>
<head>
</head>
<body>
<FORM action="RetrieveData_Post.asp" id=form1 method=post name=form1>
First Name:
<br>
<INPUT id="txtFirstName" name="txtFirstName" >
<br>
Last Name:
<br>
<INPUT id="txtLastName" name="txtLastName" >
<br>
<INPUT type="submit" value="Submit"> 
</FORM>
</body>
</html>    

这是第一页,第二页是:

<%@ Language=VBScript %>
<html>
<head>
</head>
<body>
<%
Response.Write("First Name: " & Request.Form("txtFirstName") & "<br>")
Response.Write("Last Name: " & Request.Form("txtLastName") & "<br>")
%>
</body>
</html>
4

3 回答 3

0

First, this assumes that you are running this on a server running IIS and not just double-clicking the HTML file. You need a server to process the actual code, and IIS is the most common server that will process Classic ASP.

Second, you need to make sure that ASP is enabled. Classic ASP is not enabled by default on IIS6+ (Technet)

  1. In IIS Manager, expand the local computer, and then click Web Service Extensions.
  2. In the details pane, click Active Server Pages, and then click Allow.

It may be a little different depending on the version of IIS you are running.

于 2013-10-10T12:18:32.253 回答
0

创建一个 html 页面 Gatherdata_post.htm

<html>
<head>
</head>
<body>
<FORM action="RetrieveData_Post.asp" id=form1 method=post name=form1>
    First Name:
    <br>
    <INPUT id="txtFirstName" name="txtFirstName" >
    <br>
    Last Name:
    <br>
    <INPUT id="txtLastName" name="txtLastName" >
    <br>
    <INPUT type="submit" value="Submit"> 
</FORM>
</body>
</html>

保存页面

创建一个页面 Retrievedata_post.asp

<%@ Language=VBScript %>
<html>
<head>
</head>
<body>
<%
Response.Write("First Name: " & Request.Form("txtFirstName") & "<br>")
Response.Write("Last Name: " & Request.Form("txtLastName") & "<br>")
%>
</body>
</html>

通过右键单击页面并选择在浏览器中查看来运行 Gatherdata_post.htm。通过这种方式,您可以传递值

于 2013-10-05T05:09:20.220 回答
-1

源页面

源页面有一个带有 jQ​​uery Click 事件处理程序的 HTML 按钮。单击 Button 时,会创建一个 HTML 表单并将其附加到页面的 BODY 标记中。该操作设置为目标页面 (Page2.aspx)。使用 Name TextBox 和 Technology DropDownList 的 AddParameter 函数值作为隐藏字段附加到表单,然后提交表单

<input type="button" id="btnPost" value="Send" />
<script type="text/javascript">
    $(function () {
        $("#btnPost").bind("click", function () {
            //Create a Form
            var $form = $("<form/>").attr("id", "data_form")
                            .attr("action", "Page2.aspx")
                            .attr("method", "post");
            $("body").append($form);

            //Append the values to be send
            AddParameter($form, "name", $("#txtName").val());
            AddParameter($form, "technology", $("#ddlTechnolgy").val());

            //Send the Form
            $form[0].submit();
        });
    });
    function AddParameter(form, name, value) {
        var $input = $("<input />").attr("type", "hidden")
                                .attr("name", name)
                                .attr("value", value);
        form.append($input);
    }
</script>

目标页面

在目标页面 (Page2.aspx) 上,在 ASP.Net 页面的页面加载事件中,两个已发布字段的值被获取并打印在页面上。以下代码已在 C# 中完成,但类似的可以用于其他技术。

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        if (!string.IsNullOrEmpty(Request.Form["name"]) && !string.IsNullOrEmpty(Request.Form["technology"]))
        {
            Response.Write("<u>Values using Form Post</u><br /><br />");
            Response.Write("<b>Name:</b> " + Request.Form["name"] + " <b>Technology:</b> " + Request.Form["technology"]);
        }
    }
}

优点: 同类最佳,因为 100% 保证数据也以隐藏形式发送。优点:同类最佳,因为 100% 保证数据也以隐藏形式发送。

缺点: 需要服务器端技术来获取发布的数据。需要服务器端技术来获取发布的数据。

于 2015-06-18T11:05:32.887 回答