每次加载时页面都会刷新

时间:2015-04-05 15:33:56

标签: javascript jquery asp.net

我有一个aspx页面从url获取一个值。

页面的代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="confirmpayment.aspx.cs" Inherits="AccidentCongress.UserPortal.confirmpayment" %>

       <div id="bankform"></div>

    <script language="javascript" type="text/javascript">
        function postRefId(refIdValue) {
            var form = document.createElement("form");
            form.setAttribute("method", "POST");
            form.setAttribute("action", "<% System.Configuration.ConfigurationManager.AppSettings["PgwSite"].ToString(); %>");
            form.setAttribute("target", "_self");
            var hiddenField = document.createElement("input");
            hiddenField.setAttribute("name", "RefId");
            hiddenField.setAttribute("value", refIdValue);
            form.appendChild(hiddenField); document.getElementById("bankform").appendChild(form);
            form.submit();
            document.getElementById("bankform").removeChild(form);
        }
</script>
    <%
        if (Request.QueryString["po"] == "true")
        {
            Response.Write("<script language='javascript' type='text/javascript'> postRefId('" + Request.QueryString["rid"] + "');</script>");

        }
    %>

但是当我调用此页面时,页面会刷新,并且每次都会执行这部分代码:

<%
            if (Request.QueryString["po"] == "true")
            {
                Response.Write("<script language='javascript' type='text/javascript'> postRefId('" + Request.QueryString["rid"] + "');</script>");

            }
        %>

为什么?

祝你好运

1 个答案:

答案 0 :(得分:0)

你有

 form.submit();

在你的javascript函数调用中