jQuery常用ajax操作

來源:互聯網
上載者:User

標籤:

  在做asp.net項目的時候經常會用到ajax操作,現總結常用的ajax操作供平時項目中參考

  第一種:

  前端代碼:

 

    <script type="text/javascript">        $.post("../../tools/GetItemData.ashx", { "canshu1": "參數1的值", "canshu2": "參數2的值" }, function (data) {            //返回的是json格式的資料        }, "json");    </script>

 後端代碼:

  public class ceshi : IHttpHandler    {        public void ProcessRequest(HttpContext context)        {            context.Response.ContentType = "text/plain";            string pagenumstr = context.Request["canshu1"];                       string text = context.Request["canshu2"];            //取得資料FrameHtml            context.Response.Write(new JavaScriptSerializer().Serialize(FrameHtml));        }    }

 說明:

 if Request.QueryString("ID")==Null這是url欄沒有這個ID變數
 if Request.QueryString("ID").ToString()=="" 判斷ID是否為空白

 

  第二種:

 

  前端代碼:

<script type="text/javascript">            //驗證是否登入    $.ajax({                 type: "POST",        url: "{config.webpath}tools/submit_ajax.ashx?action=user_check_login",        dataType: "json",        timeout: 20000,        success: function (data, textStatus) {            if (data.status == 1) {                                           }         }    });</script>

 後端代碼:

 public void ProcessRequest(HttpContext context)        {            //取得處事類型            string action = EazyRequest.GetQueryString("action");            switch (action)            {                                case "user_check_login": //檢查使用者是否登入                    user_check_login(context);                    break;                                case "applyspace": //更新申請                    apply_user_space(context);                    break;            }        }#region 檢查使用者是否登入=============================        private void user_check_login(HttpContext context)        {            //檢查使用者是否登入            Model.users model = new BasePage().GetUserInfo();            if (model == null)            {                context.Response.Write("{\"status\":0, \"username\":\"匿名使用者\"}");                return;            }            context.Response.Write("{\"status\":1, \"username\":\"" + model.user_name + "\", \"userid\":\"" + model.id + "\", \"zuid\":\"" + model.group_id + "\"}");        }        #endregion

 

jQuery常用ajax操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.