This article introduces JQuery's example code for getting json data $. getJSON. If you need it, refer to the front-end:
The Code is as follows:
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 + =" "+ Item. description +" ";
StrDeviceTr + =" ";
StrDeviceTr + =" "+ Item. hoursdays +" ";
StrDeviceTr + ="0.8";
StrDeviceTr + =" "+ Item. workinghour +" ";
StrDeviceTr + ="0.8";
StrDeviceTr + =" "+ Item. workinghour +" ";
StrDeviceTr + =" ";
StrDeviceTr + ="";
});
$ ("# Infor"). append (strDeviceTr );
});
}
}
Ashx
The Code is as follows:
String innerid = CommonClass. Request. GetRequest ("InnerID ","");
String key = CommonClass. Request. GetRequest ("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 statement Information
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 ("An error occurred while obtaining the project! [Exception information: "+ 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 ("An error occurred while obtaining the project! [Exception information: "+ ex. Message +"] ", AppLog. LogMessageType. Info );
Return string. Empty;
}
}
# Endregion