JS中擷取資料庫中的值的方法

來源:互聯網
上載者:User

實施過程如下:
    1、引用Ajax.dll
    2、在App_Code寫具體的方法,最好單獨建立一個類檔案,然後寫具體方法。      
複製代碼 代碼如下:
public class AjaxMethod www.jb51.net
{
    public AjaxMethod()
    {
        //
        //TODO: 在此處添加建構函式邏輯
        //
    }
    [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中調用
複製代碼 代碼如下:
moneydiscount= AjaxMethod.GetCardMoney(card, pwd).value;
moneydiscount//是一個多個值拼接成的字串,要擷取多個值的話,可以把該字串轉換為一個數組,然後去訪問。
arr=moneydiscount.split(",");        //這樣的話可以很方便的使用Ajax返回多個值。

4、要把結果再返回到頁面中
複製代碼 代碼如下:
document.getElementById("txtCard_Money1").value=arr[0];

5、以上方法要在Web.config檔案中增加
複製代碼 代碼如下:
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
</httpHandlers>

今天的內容就寫到這裡,以後有時間再慢慢寫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.