僅用aspx檔案實現Ajax調用後台cs程式。(執行個體)

來源:互聯網
上載者:User

標籤:ajax   執行個體   

僅用aspx檔案實現Ajax調用後台cs無重新整理程式。(執行個體)

兩個檔案:aaa.aspx 和aaa.aspx.cs

一、aaa.aspx 

<script type="text/javascript">             function Request() {            alert("1");            $.ajax({                type: 'post',                url: 'Test442.aspx?method=Send2',   // 【調用背景事件】                cache: false,                success: function (data) {                    if (data == '00000') {                        //receive();                    }                    var tbReceive = $('#tbReceive').val();                    $('#tbReceive').val(tbReceive + data + ";");                },                error: function (XMLHttpRequest, textStatus) {                }            });        };    </script>

二、aaa.aspx.cs

protected void Page_Load(object sender, EventArgs e)    {        string result = "";        if (!IsPostBack)        {            if (Request["method"] != null)            {                try                {                    switch (Request.QueryString["method"])                    {                        case "Send2":                                                          result = Send2();   <span style="font-family: Arial, Helvetica, sans-serif;">// 【執行的事件send2】</span>                            break;                    }                }                catch (Exception ex)                {                    result = ex.Message;                    LogManager.WriteLog(ex.Message);                }                Response.Clear();                Response.ContentType = "text/plain";                Response.ContentEncoding = System.Text.Encoding.UTF8;                Response.Write(result);                Response.End();            }        }    }


僅用aspx檔案實現Ajax調用後台cs程式。(執行個體)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.