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 相关文章推荐
从新浪弄下来的全屏广告代码 与使用说明
Mar 15 Javascript
分步解析JavaScript实现tab选项卡自动切换功能
Jan 25 Javascript
精通JavaScript的this关键字
May 28 Javascript
基于jquery插件实现拖拽删除图片功能
Aug 27 Javascript
JavaScript 继承详解(六)
Oct 11 Javascript
JavaScript交换两个变量值的七种解决方案
Dec 01 Javascript
JavaScript制作弹出层效果
Dec 02 Javascript
javascript实现简易计算器
Feb 01 Javascript
React Native react-navigation 导航使用详解
Dec 01 Javascript
前端Vue项目详解--初始化及导航栏
Jun 24 Javascript
如何区分vue中的v-show 与 v-if
Sep 08 Javascript
JavaScript/TypeScript 实现并发请求控制的示例代码
Jan 18 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 curl 登录163邮箱并抓取邮箱好友列表的代码(经测试)
2011/04/07 PHP
谈谈你对Zend SAPIs(Zend SAPI Internals)的理解
2015/11/10 PHP
ThinkPHP3.2.3实现分页的方法详解
2016/06/03 PHP
javascript-TreeView父子联动效果保持节点状态一致
2007/08/12 Javascript
CLASS_CONFUSION JS混淆 全源码
2007/12/12 Javascript
JS 中document.URL 和 windows.location.href 的区别
2009/11/11 Javascript
JavaScript中定义类的方式详解
2016/01/07 Javascript
node.js+express制作网页计算器
2016/01/17 Javascript
无缝滚动的简单实现代码(推荐)
2016/06/07 Javascript
利用JQuery实现datatables插件的增加和删除行功能
2017/01/06 Javascript
微信小程序 页面传值详解
2017/03/10 Javascript
JS实现数组按升序及降序排列的方法
2017/04/26 Javascript
vue.js+Echarts开发图表放大缩小功能实例
2017/06/09 Javascript
在原生不支持的旧环境中添加兼容的Object.keys实现方法
2017/09/11 Javascript
详解vue-cli与webpack结合如何处理静态资源
2017/09/19 Javascript
Vue 实现把表单form数据 转化成json格式的数据
2019/10/29 Javascript
Vue select 绑定动态变量的实例讲解
2020/10/22 Javascript
Vue-Ant Design Vue-普通及自定义校验实例
2020/10/24 Javascript
基于anaconda下强大的conda命令介绍
2018/06/11 Python
win10下python3.5.2和tensorflow安装环境搭建教程
2018/09/19 Python
python矩阵的转置和逆转实例
2018/12/12 Python
浅谈python 导入模块和解决文件句柄找不到问题
2018/12/15 Python
python输出电脑上所有的串口名的方法
2019/07/02 Python
python实现生成Word、docx文件的方法分析
2019/08/30 Python
css3 利用transform打造走动的2D时钟
2020/10/20 HTML / CSS
Sneaker Studio捷克:购买运动鞋
2018/07/08 全球购物
StubHub澳大利亚:购买或出售您的门票
2019/08/01 全球购物
Android面试宝典
2013/08/06 面试题
WSDL的操作类型主要有几种
2013/07/19 面试题
鉴定评语大全
2014/05/05 职场文书
副校长个人对照检查材料思想汇报
2014/10/04 职场文书
2015幼儿园庆元旦活动方案
2014/12/09 职场文书
本科毕业论文指导教师评语
2014/12/30 职场文书
2015年法制宣传月活动总结
2015/03/26 职场文书
解决redis批量删除key值的问题
2022/03/23 Redis
Python正则表达式中flags参数的实例详解
2022/04/01 Python