Home  >  Article  >  Web Front-end  >  How to get the value in the database in JS_javascript skills

How to get the value in the database in JS_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:28:391319browse

The implementation process is as follows:
1. Reference Ajax.dll
2. Write specific methods in App_Code. It is best to create a separate class file and then write specific methods.

Copy code The code is as follows:

public class AjaxMethod www.jb51.net
{
public AjaxMethod()
{
//TODO: Add constructor logic here
//
}
[Ajax.AjaxMethod(Ajax.HttpSessionState Requirement .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;//Return here a string composed of multiple values ​​​​
   }
}

3. Called in JS

Copy code The code is as follows:
moneydiscount= AjaxMethod.GetCardMoney(card, pwd).value ;
moneydiscount// is a string composed of multiple values. If you want to get multiple values, you can convert the string into an array and then access it.
arr=moneydiscount.split(","); //In this case, it is very convenient to use Ajax to return multiple values.

4. To return the results to the page

Copy the code The code is as follows:
document.getElementById("txtCard_Money1").value=arr[0];

5. For the above method, add

to the Web.config file
Copy code The code is as follows:




That’s it for today. I’ll finish it later if I have time. write slowly
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn