How to get the value in the database in JS _javascript tips

Source: Internet
Author: User
The implementation process is as follows:
1. Quote Ajax.dll
2, in the App_Code to write specific methods, it is best to create a separate class file, and then write the specific method.
Copy Code code as follows:

public class Ajaxmethod Www.jb51.net
{
Public Ajaxmethod ()
{
//
TODO: Add 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.executeselectsql ("Select Card_money,service_discount,good_discount from Table_cardinfo join Dic_") Cardtype on table_cardinfo.cardtype_id= dic_cardtype.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;//here Returns a string of multiple values concatenation
}
}

3, in the JS call
Copy Code code as follows:

Moneydiscount= Ajaxmethod.getcardmoney (Card, pwd). value;
moneydiscount//is a string of multiple values that, to get multiple values, can be converted to an array and then accessed.
Arr=moneydiscount.split (","); This makes it easy to use AJAX to return multiple values.

4, to return the results to the page
Copy Code code as follows:

document.getElementById ("Txtcard_money1"). Value=arr[0];

5, the above methods to be added in the Web.config file
Copy Code code as follows:

<add verb= "Post,get" path= "Ajax/*.ashx" type= "Ajax.pagehandlerfactory, Ajax"/>

Today's content is written here, later have time to write slowly

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.