首页  >  文章  >  web前端  >  JQuery 获取json数据$.getJSON方法的实例代码_jquery

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

WBOY
WBOY原创
2016-05-16 17:27:221022浏览

 前台:
 

复制代码 代码如下:

 function SelectProject() {
            var a = new Array;
            var r = window.showModalDialog('SelProject.aspx', a, "dialogWidth=1000px;dialogHeight=600px; 可调整大小:是");
            if (typeof (r) != '未定义') {
                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 = " " item.description " ";
                              strDeviceTr = "   ";
                                strDeviceTr = " ";
                                strDeviceTr = ";  0.8";
                                strDeviceTr = " " item.workinghour " ";
                                strDeviceTr = ";  0.8";
                                strDeviceTr = " " item.workinghour "";
                                strDeviceTr = ";  ";
                                strDeviceTr = "";
                             });
                            $("#infor").append(strDeviceTr);
                        });
            }
        }
 
 ashx
 
复制代码 代码如下:

 string insideid = CommonClass.Request.GetRequest("InnerID", "");
            string key = CommonClass.Request.GetRequest("key", "");
            string result = "";
            if (key == "StockOutApp" && insideid != "")
            {
                result = StockOutApp(innerid);
                context.Response.Write(结果);
            }
            else if (key == "PaymentStatement" && insideid != "")
            {
                result = PaymentStatement(innerid);
                context.Response.Write(结果) ;
            }
#region 结算单信息
        public string PaymentStatement(string _innerid)
        {
            尝试
            {
                string sql = @"选择 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
                {
                    返回字符串.空;
               }
            }
            catch (异常)
            {
                AppLog.Write("项目获取异常![异常信息:" ex.Message "]", AppLog.LogMessageType.Info);
                return string.Empty;
            }
        }
        public string GetWorkingHours(string _innerid)
        {
            尝试
            {
               string sql = @"从 se_ProjectWorkingHour 中选择 InnerID、wDescription、wWorkingHour、wHours_Days,其中 wProjectID='" _innerid "'";
                DataTable dt = SqlShift.GetDataTable(sql);
                if (!CommonClass.DTRow.CheckDtIsEmpty(dt))
                {
                   StringBuilder json = new StringBuilder();
                  (int i = 0; i                     {
                       json.Append("{");
                        json.Append(""innerid":"dt.Rows[0]["In nerID"].ToString() """);
                        json.Append(","description":"" dt.Rows[0]["wDescription"].ToString() """);
                         json.Append(","工作时间":"" dt .Rows[0]["wWorkingHour"].ToString() """);
                        json.Append(","hoursdays":"" dt.Rows[0]["wHours_Days"].ToString() " "");
                        json.Append("},");
                    }
                     return "[" json.ToString().Trim(',') "]";
                }
                else
                {
                   返回字符串.空;
                }
            }
            catch (Exception ex)
            {
                AppLog.Write("项目获取异常![异常信息: " ex.Message "]", AppLog.LogMessageType.Info);
                return string.Empty;
            }
        }
        #endregion
 
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn