欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS中獲取數(shù)據(jù)庫中的值的方法

 更新時間:2013年07月14日 15:33:16   作者:  
在項目中遇到一個問題,需要在JS中讀取數(shù)據(jù)庫中的值,然后再把值返回到頁面中,解決方案如下:使用Ajax方法來實現(xiàn),需要用到ajax.dll(一個ajax技術(shù)開發(fā)的幫助類庫)。
實施過程如下:
    1、引用Ajax.dll
    2、在App_Code寫具體的方法,最好單獨建立一個類文件,然后寫具體方法。      
復制代碼 代碼如下:

public class AjaxMethod www.dbjr.com.cn
{
    public AjaxMethod()
    {
        //
        //TODO: 在此處添加構(gòu)造函數(shù)邏輯
        //
    }
    [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='正常'");
        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;//此處返回一個多個值拼接成的字符串
    }
}

3、在JS中調(diào)用
復制代碼 代碼如下:

moneydiscount= AjaxMethod.GetCardMoney(card, pwd).value;
moneydiscount//是一個多個值拼接成的字符串,要獲取多個值的話,可以把該字符串轉(zhuǎn)換為一個數(shù)組,然后去訪問。
arr=moneydiscount.split(",");        //這樣的話可以很方便的使用Ajax返回多個值。

4、要把結(jié)果再返回到頁面中
復制代碼 代碼如下:

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

5、以上方法要在Web.config文件中增加
復制代碼 代碼如下:

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

今天的內(nèi)容就寫到這里,以后有時間再慢慢寫

相關(guān)文章

最新評論