JQuery 获取json数据$.getJSON方法的实例代码


Posted in Javascript onAugust 02, 2013

 前台:
 

 function SelectProject() {
            var a = new Array;
            var r = window.showModalDialog('SelProject.aspx', a, "dialogWidth=1000px; dialogHeight=600px; resizable: yes");
            if (typeof (r) != 'undefined') {
                var arr = r.split(";");
                $("#hidProjectInnerID").val(arr[0]);
                $("#txtProjectNo").val(arr[1]);
                $.getJSON("../Handler/GetProjectInfor.ashx", { key: "PaymentStatement", InnerID: $("#hidProjectInnerID").val() },
                        function (json) {
                            $("#labFinalCustomer").text(json.finalclient);
                            $("#labOrderNo").text(json.orderno);
                            var strDeviceTr = "";
                            $.each(json.workinghours, function (i, item) {
                                strDeviceTr += "<tr><td><lable name="infor"> " + item.description + "</lable> </td>";
                                strDeviceTr += "<td>   </td>";
                                strDeviceTr += " <td><lable name="infor"> " + item.hoursdays + "</lable></td>";
                                strDeviceTr += "<td>  0.8</td>";
                                strDeviceTr += "<td><lable name="infor"> " + item.workinghour + " </lable></td>";
                                strDeviceTr += "<td>  0.8</td>";
                                strDeviceTr += "<td><lable name="infor"> " + item.workinghour + "</lable></td>";
                                strDeviceTr += "<td>  </td>";
                                strDeviceTr += "</tr>";
                            });
                            $("#infor").append(strDeviceTr);
                        });
            }
        }
 

 ashx
 
 string innerid = CommonClass.Request.GetRequest<string>("InnerID", "");
            string key = CommonClass.Request.GetRequest<string>("key", "");
            string result = "";
            if (key == "StockOutApp" && innerid != "")
            {
                result = StockOutApp(innerid);
                context.Response.Write(result);
            }
            else if (key == "PaymentStatement" && innerid != "")
            {
                result = PaymentStatement(innerid);
                context.Response.Write(result);
            }
#region 结算单信息
        public string PaymentStatement(string _innerid)
        {
            try
            {
                string sql = @"select InnerID,pFinalClient,pOrderNo from se_ProjectMain where InnerID='" + _innerid + "'";
                DataTable dt = SqlShift.GetDataTable(sql);
                if (!CommonClass.DTRow.CheckDtIsEmpty(dt))
                {
                    StringBuilder json = new StringBuilder();
                     json.Append(""innerid":""+dt.Rows[0]["InnerID"].ToString()+""");
                     json.Append(","finalclient":"" + dt.Rows[0]["pFinalClient"].ToString() + """);
                     json.Append(","orderno":"" + dt.Rows[0]["pOrderNo"].ToString() + """);
                    json.Append(","workinghours":" + GetWorkingHours(_innerid));
                    return "{" + json.ToString().Trim(',') + "}";
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                AppLog.Write("项目获取异常![异常信息:" + ex.Message + "]", AppLog.LogMessageType.Info);
                return string.Empty;
            }
        }
        public string GetWorkingHours(string _innerid)
        {
            try
            {
                string sql = @"select InnerID, wDescription,wWorkingHour,wHours_Days from se_ProjectWorkingHour where wProjectID='" + _innerid + "'";
                DataTable dt = SqlShift.GetDataTable(sql);
                if (!CommonClass.DTRow.CheckDtIsEmpty(dt))
                {
                    StringBuilder json = new StringBuilder();
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        json.Append("{");
                        json.Append(""innerid":"" + dt.Rows[0]["InnerID"].ToString() + """);
                        json.Append(","description":"" + dt.Rows[0]["wDescription"].ToString() + """);
                        json.Append(","workinghour":"" + dt.Rows[0]["wWorkingHour"].ToString() + """);
                        json.Append(","hoursdays":"" + dt.Rows[0]["wHours_Days"].ToString() + """);
                        json.Append("},");
                    }
                    return "[" + json.ToString().Trim(',') + "]";
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                AppLog.Write("项目获取异常![异常信息:" + ex.Message + "]", AppLog.LogMessageType.Info);
                return string.Empty;
            }
        }
        #endregion 
 
Javascript 相关文章推荐
jquery延迟加载外部js实现代码
Jan 11 Javascript
jQuery中的height innerHeight outerHeight区别示例介绍
Jun 15 Javascript
node.js中的定时器nextTick()和setImmediate()区别分析
Nov 26 Javascript
JavaScript 面向对象与原型
Apr 10 Javascript
JavaScript动态修改背景颜色的方法
Apr 16 Javascript
在AngularJS中使用jQuery的zTree插件的方法
Apr 21 Javascript
javascript中JSON.parse()与eval()解析json的区别
May 19 Javascript
vue2.0父子组件间通信的实现方法
Apr 19 Javascript
jquery+css实现简单的图片轮播效果
Aug 07 jQuery
AngularJS 仿微信图片手势缩放的实例
Sep 28 Javascript
仿vue-cli搭建属于自己的脚手架的方法步骤
Apr 17 Javascript
Vue的click事件防抖和节流处理详解
Nov 13 Javascript
可简单避免的三个JS发布错误的详细介绍
Aug 02 #Javascript
Js控制弹窗实现在任意分辨率下居中显示
Aug 01 #Javascript
Jquery同辈元素选中/未选中效果的实例代码
Aug 01 #Javascript
解决js数据包含加号+通过ajax传到后台时出现连接错误
Aug 01 #Javascript
Javascript 遮罩层和加载效果代码
Aug 01 #Javascript
JS防止用户多次提交的简单代码
Aug 01 #Javascript
纯文字版返回顶端的js代码
Aug 01 #Javascript
You might like
php下防止单引号,双引号在接受页面转义的设置方法
2008/09/25 PHP
PHP中判断变量为空的几种方法分享
2013/08/26 PHP
php使用FFmpeg接口获取视频的播放时长、码率、缩略图以及创建时间
2016/11/07 PHP
Javascript+XMLHttpRequest+asp.net无刷新读取数据库数据
2009/08/09 Javascript
Jquery实现简单的动画效果代码
2012/03/18 Javascript
基于jQuery实现左右div自适应高度完全相同的代码
2012/08/09 Javascript
关于textarea提交的内容无法换行的解决办法
2013/04/09 Javascript
javascript获取select的当前值示例代码(兼容IE/Firefox/Opera/Chrome)
2013/12/17 Javascript
jquery使用animate方法实现控制元素移动
2015/03/27 Javascript
JavaScript获取页面中表单(form)数量的方法
2015/04/03 Javascript
javascript封装的sqlite操作类实例
2015/07/17 Javascript
javascript 数组的定义和数组的长度
2016/06/07 Javascript
AngularJS基础 ng-open 指令简单实例
2016/08/02 Javascript
详解nodejs微信jssdk后端接口
2017/05/25 NodeJs
JS获取一个字符串中指定字符串第n次出现的位置
2021/02/10 Javascript
python实现查找excel里某一列重复数据并且剔除后打印的方法
2015/05/26 Python
python学生信息管理系统
2018/03/13 Python
基于循环神经网络(RNN)实现影评情感分类
2018/03/26 Python
儿童python练习实例
2018/05/27 Python
python七夕浪漫表白源码
2019/04/05 Python
Django中URL的参数传递的实现
2019/08/04 Python
python 线性回归分析模型检验标准--拟合优度详解
2020/02/24 Python
解决Opencv+Python cv2.imshow闪退问题
2020/04/24 Python
python实现批量转换图片为黑白
2020/06/16 Python
css3弹性盒模型实例介绍
2013/05/27 HTML / CSS
CSS3 3D酷炫立方体变换动画的实现
2019/03/26 HTML / CSS
Hotels.com印度:酒店预订
2019/05/11 全球购物
电脑销售顾问自荐信
2014/01/29 职场文书
服装采购员岗位职责
2014/03/15 职场文书
建设投标担保书
2014/05/13 职场文书
爱祖国爱家乡演讲稿
2014/09/02 职场文书
2015年学校后勤工作总结
2015/04/08 职场文书
2016年校园植树节广播稿
2015/12/17 职场文书
外出考察学习心得体会
2016/01/18 职场文书
Go 实现英尺和米的简单单位换算方式
2021/04/29 Golang
PyTorch中的torch.cat简单介绍
2022/03/17 Python