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 ;

            }

  • 相关阅读:
    用PHP判断oicq是否在线的小程序
    我的PHP树的代码,可以嵌套任意层
    用PEAR来写你的下一个php程序(潘凡Night Sailer)(1)
    php在线文本编辑器
    分析HTML,并将结果存到一个数组中。看看里面的注释吧。:)
    聊天室php
    基于文件、数据库的计数器
    hust The mell hell
    UVA 10003 Cutting Sticks(区间DP)
    zoj 3197 Google Book(最小区间覆盖)
  • 原文地址:https://www.cnblogs.com/piguo/p/5112351.html
Copyright © 2011-2022 走看看