zoukankan      html  css  js  c++  java
  • JS中获取数据库中的值

    在本次项目中,遇到很多问题,经过努力,都逐步得到解决。静下心来,做一个记录,以供以后学习。

        在项目中遇到一个问题,需要在JS中读取数据库中的值,然后再把值返回到页面中,解决方案如下:使用Ajax方法来实现,需要用到ajax.dll(一个ajax技术开发的帮助类库)。

        实施过程如下:

        1、引用Ajax.dll

        2、在App_Code写具体的方法,最好单独建立一个类文件,然后写具体方法。       

    public class AjaxMethod www.2cto.com

    {

        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>

       今天的内容就写到这里,以后有时间再慢慢写

    摘自:让你望见影子的墙

  • 相关阅读:
    FZU Problem 2169 shadow
    tomcat配置虚拟主机
    数据库设计中的14个技巧
    JSP动作--JSP有三种凝视方式
    BoundsChecker使用
    个人收藏的flex特效网址【经典中的极品】
    C++中的explicitkeyword
    Andorid Binder进程间通信---Binder本地对象,实体对象,引用对象,代理对象的引用计数
    深入浅出JMS(一)——JMS简单介绍
    一个有意思的编程练习站点
  • 原文地址:https://www.cnblogs.com/yuhuameng/p/3907183.html
Copyright © 2011-2022 走看看