JQuery: Get json data $. getJSON Method Instance code _ jquery

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.