Get database values in JS

Source: Internet
Author: User

 

In this project, many problems have been solved step by step through hard work. Calm down and make a record for future study.

 

If you encounter a problem in the project, you need to read the value in the database in JS and then return the value to the page. The solution is as follows: Ajax is used for implementation and ajax is required. dll (a help class library for ajax technology development ).

 

The implementation process is as follows:

 

1. Reference Ajax. dll

 

2. Write a specific method in App_Code. It is best to create a class file separately and then write a specific method.

 

Public class AjaxMethod www.2cto.com

{

Public AjaxMethod ()

{

//

// TODO: add the constructor logic here

//

}

[Ajax. AjaxMethod (Ajax. HttpSessionStateRequirement. Read)]

Public static string GetCardMoney (string cardNo, string cardPwd)

{

String mConn = IConfiguration. getParameter ("connectString ");

IDBOSQL. IDBO dbo = IDBOSQL. IDBO. getIDBO (mConn );

Dbo. openDatabase ();

DataSet ds = dbo.exe cuteSelectSql ("select Card_Money, Service_Discount, good_Discount from Table_CardInfo join Dic_CardType on Table_CardInfo.CardType_ID = where Card_NO = '"+ cardNo +"' and Card_Pwd = '"+ cardPwd +"' and card_Status = 'normal '");

DataTable dt = ds. Tables [0];

String money = dt. Rows [0] [0]. ToString ();

String service_discount = dt. Rows [0] [1]. ToString ();

String good_discount = dt. Rows [0] [2]. ToString ();

Dbo. closeDatabase ();

Return money + "," + service_discount + ',' + good_discount; // return a string concatenated by multiple values.

}

}

3. Call in JS

Moneydiscount = AjaxMethod. GetCardMoney (card, pwd). value;

Moneydiscount is a string concatenated by multiple values. To obtain multiple values, you can convert the string into an array and then access it.

Arr = moneydiscount. split (","); in this way, Ajax can be easily used to return multiple values.

4. Return the result to the page.

Document. getElementById ("txtCard_Money1"). value = arr [0];

5. Add the preceding Method to the Web. config file.

<HttpHandlers>

<Add verb = "POST, GET" path = "ajax/*. ashx" type = "Ajax. PageHandlerFactory, Ajax"/>

</HttpHandlers>

Today's content is written here, and I will write it later.

From: a wall that allows you to see shadows

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.