欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-10-31 08:10:37
代码如下:  function selectproject() {         ...

代码如下:


 function selectproject() {
            var a = new array;
            var r = window.showmodaldialog('selproject.x', 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);
      &nbsnbsp;     }
            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