码迷,mamicode.com
首页 > 其他好文 > 详细

ajax利用session传值到前台(案例)

时间:2014-06-08 19:12:12      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:des   c   style   class   blog   code   

后台:

bubuko.com,布布扣
 public static string TrendChart()
        {
            HttpContext context = HttpContext.Current;
            ReturnStr strReturn = new ReturnStr();
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            strReturn.msg = serializer.Serialize(list);
            strReturn.other = ExcelName;
            strReturn.oldname = priceType;
            strReturn.count = ProductID.Count;
            strReturn.success = true;
            if (context.Session["Object"] != null)
            {
                context.Session.Remove("Object");
            }
            context.Session["Object"] = strReturn;
            return serializer.Serialize(strReturn);
        }
bubuko.com,布布扣

前台:

bubuko.com,布布扣
 $("#btnTrendChart").bind("click", function () {
            var jsonData = {
                path: "/CollectAnalysis/LivelihoodAnalysis/ViewProductDetails.aspx/TrendChart",
                param: {}
            }
            var resultData = _Fun.jQueryAjax(jsonData);
            if (resultData.info) {
                WindowsOutOpen("ProductTrendChart.aspx");
            }                 
        });
bubuko.com,布布扣

还可以

bubuko.com,布布扣
 $("#btnTrendChart").bind("click", function () {
            var jsonData = {
                path: "/CollectAnalysis/LivelihoodAnalysis/ViewProductDetails.aspx/TrendChart",
                param: {}
            }
            var _myJson = { info: true };
            showProgress(0, "正在整理数据中,请稍候...");
            $.ajax({
                type: "POST",
                async: true,
                url: jsonData.path,
                data: JSON.stringify(jsonData.param),
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                success: function (data) {
                    _myJson.info = JSON.parse(data.d);
                    if (_myJson.info.success) {
                        WindowsOutOpen("ProductTrendChart.aspx");
                    }
                    hideProgress();
                },
                error: function () {
                    hideProgress();
                    error(服务器未响应,请联系管理员!);
                }
            });            
        });
bubuko.com,布布扣

这种可以添加进度条:showProgress(0, "正在整理数据中,请稍候...");

ProductTrendChart.aspx后台代码:

bubuko.com,布布扣
 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    if (Session["Object"] == null)
                    {
                        //如果没有要导出的Session对象
                        return;
                    }
                    jsonObject = Session["Object"] as ReturnStr;
                    string jsonlist = jsonObject.msg;
                    JavaScriptSerializer Serializer = new JavaScriptSerializer();
                    list = Serializer.Deserialize<List<Models.livelihooddatachecked>>(jsonlist);
                }
                catch { }
            }
        }
bubuko.com,布布扣

 

ajax利用session传值到前台(案例),布布扣,bubuko.com

ajax利用session传值到前台(案例)

标签:des   c   style   class   blog   code   

原文地址:http://www.cnblogs.com/gbnw/p/3776097.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!