ajax向aspx后台请求时返回的数据怎么连前台的代码一块返回

前台代码:

$(function myfunction() {
$.ajax({
type: "Post",
url: "WebForm1.aspx",
data: { aaaa:1,bbbb:2 },
dataType: "text",
success: function (data) {
alert(data);

}
});
});

            后台:
         protected void Page_Load(object sender, EventArgs e)
    {          
        if (!IsPostBack)
        {
            var aaa = Request["aaaa"];
            var bbb = Request["bbbb"];
            //Response.End();        
            Response.Write(aaa + bbb);
        }                     
    }




            结果:

    12
    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title>    <script src="jquery-3.3.1.min.js"></script>    <script type="text/javascript">        $(function myfunction() {            $.ajax({                type: "Post",                url: "WebForm1.aspx",                data: { aaaa:1,bbbb:2 },                dataType: "text",                success: function (data) {                    $("#txt1").val(data);                    alert(data);                                  }            });        });    </script></head><body>    <form method="post" action="./WebForm1.aspx" id="form1"><div class="aspNetHidden"><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="PXGntMhDLvKIfR78Lo4ZTiLH+YRHlxQBtKts3lMiSVzRTCMJHg25UPMVz/CXnn6yxDKMDshxP3lT3e8C6ua0rG3owcUyY8o2/pEZC/0GcGA=" /></div><div class="aspNetHidden">  <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="B6E7D48B" /></div>        <div>            <input type="text" id="txt1"/>        </div>    </form></body></html>

1个回答

Response.Write(aaa + bbb);
Response.Flush();
Response.End();

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!