zoukankan      html  css  js  c++  java
  • 在js 中使用ajax 调用后台代码方法,解析返回值

     一 . 在js 中使用ajax  调用后台代码方法,解析返回值

    1 ajax 请求格式

      $.ajax({

                type: "Post",

                url: "/coupons.aspx/AllVouchers",

                contentType: "application/json",

                data: "{'index': '" + index + "', 'status': '" + status + "'}",

                dataType: 'json',

            success: function (data) {

                data = JSON.parse(data.d);  

               }

    });

    $.ajax({

            type: "Post",

            url: "/coupons.aspx/AllVouchersCount",

            contentType: "application/json",

            data: "{ 'status': '" + status + "'}",

            dataType: 'json',

            success: function (data) {

              

                data= eval("(" + data.d + ")").result;

               }

    });

    2  后台方法

    //列表

      public partial class coupons : System.Web.UI.Page

     {

            [WebMethod]

            public static string AllVouchers(string index,string status )

            {

                int pageindex = Convert.ToInt32(index);

                int page = 9;

     

                string uid = "";

                if (HttpContext.Current.Session["uid"] == null)

                {

                    HttpContext.Current.Response.Redirect("login.aspx");

                }

                else

                {

                    uid = PubEncryptionFunc.PublicDecrypt(HttpContext.Current.Session["uid"].ToString());

                }

     

                return JsonConvert.SerializeObject(COUPON_DAIJIN.getInstanct().DsCoupon_DaiJin(uid, status, pageindex, page));

            }

        //总计录数

            [WebMethod]

            public static  string AllVouchersCount(string status)

            {

                string uid = "";

                if (HttpContext.Current.Session["uid"] == null)

                {

                    HttpContext.Current.Response.Redirect("login.aspx");

                }

                else

                {

                    uid = PubEncryptionFunc.PublicDecrypt(HttpContext.Current.Session["uid"].ToString());

                }

               string json = "{"result":""+ COUPON_DAIJIN.getInstanct().Coupon_DaiJinCount(uid, status).ToString() + ""}";

                return json ;

            }

  • 相关阅读:
    【常见问题汇总--持续更新】bootloader常见问题
    UCD9222 EN1/EN2
    cdce62005配置说明
    xilinx planahead partial reconfiguration
    诺基亚 920T
    不出现用户帐户控制-让Win7的用户账户控制(UAC)放过信任的程序
    python 拷贝文件夹下的文件 到 另一个文件夹
    python 计算两个日期间的小时数
    shell 解析 json
    shell 脚本运行 hive sql
  • 原文地址:https://www.cnblogs.com/piguo/p/5112351.html
Copyright © 2011-2022 走看看