zoukankan      html  css  js  c++  java
  • asp.net ajax的使用

    参考:https://www.cnblogs.com/acles/articles/2385648.html

    https://www.cnblogs.com/xujingyang/p/5560646.html

    1.请求aspx页面后台中的方法,带参数

    前台

    $.ajax({
                    type: "Post",
                    url: "ResponsePage.aspx/RequestMethod1",
                    data:"{'msg':'hello'}",
                    contentType: "application/json;charset=utf-8",// 这句可不要忘了。
                    dataType: "json",
                    success: function (res) {
                        $("#dataShow").text("success:" + res.d); // 注意有个d,至于为什么通过chrome看响应吧,O(∩_∩)O。
                    },
                    error: function (xmlReq, err, c) {
                        $("#dataShow").text("error:" + err);
                    }
                });

    后台:

    [WebMethod]
    public static string RequestMethod1(string msg)
    {
          return msg;
     }

    2.一般处理程序(ashx)

    前台

    function test(id,pwd){
                $.ajax({
                    url: '/Tools/Handler.ashx?action=test',
                    data:{id : id, pwd : pwd },
                    success: function (data){
                        alert(data.data);
                    }
                });
            }

    后台

    HttpRequest _request;
        HttpResponse _response;
        public void ProcessRequest(HttpContext context)
            {
               _request = context.Request;
               _response = context.Response;
                context.Response.ContentType = "application/json";
                string action = context.Request["action"].ToString();
    //string action = _request.QueryString["action"] + "";
    switch (action) { case "test": test(context); break; default: break; } } public void test(HttpContext context) { string id = context.Request["id"].ToString(); string pwd = context.Request["pwd"].ToString(); ///代码段 /// List<int> list = new List<int>(); list.add(1); vat data = JsonConvert.SerializeObject(list); HttpContext.Current.Response.Write("data:"+data); }
  • 相关阅读:
    题解报告——垃圾陷阱
    后缀自动机
    计算几何之凸包
    平衡树——treap
    图论--最小费用最大流(MCMF)
    很重要的吐槽!
    图论--网络流初步(最大流,增广路)
    字符串--Trie树(字典树)
    图论--Tarjan求强联通分量
    数据结构--堆
  • 原文地址:https://www.cnblogs.com/zhang1f/p/11115413.html
Copyright © 2011-2022 走看看