Ajax



<script type="text/javascript">
        function btnClick() {
            var xmlHttp = null;
            if(window.ActiveXObject){
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if(window.XMLHttpRequest){
            xmlHttp = new  XMLHttpRequest();
            }
           if(!xmlHttp){
               alert("error from create a xmlHttp! ");
               return;
           }
           var moneyType = $("#selectId").val();
           var account = $("#myAccount").val();
    
           //用到中文字符都要用encodeURl来转化字符类型,不仅仅是参数,页面名称亦如是
           //xmlhttp.open("POST", "02" + encodeURI('汇率问题') + ".ashx?moneyType=" + moneyType + "&account=" + account + "&ts=" + new Date(), false);

//           xmlHttp.open("post", "Get_02Ajax.ashx?moneyType=" + moneyType + "&account=" + account + "&ts =" + new Date(), false);
           xmlHttp.open("post", "Get_02Ajax.ashx?moneyType=" + moneyType + "&account=" + account , false);
           xmlHttp.onreadystatechange = function () {
               if (xmlHttp.readyState == 4) {
                   if (xmlHttp.status == 200) {
                       $("#txtResult").val(xmlHttp.responseText);
                   }
               }
           }
           xmlHttp.send();
        }
    </script>


 <form id="form1" runat="server">
    <div>
     <input type ="text" id="myAccount" name="myAccount"  style="width:150px;height:30px;"/>
     <select id ="selectId">
        <option value="1"  selected="selected" > dollar </option>
        <option value="2"> RMB</option>
        <option value="3">Japan</option>
     </select>
     <input type="button" name="rateConvert" id="rateConvert" οnclick="btnClick()" value ="汇率转换" />
     <input type="text" id="txtResult" name="txtResult"  style="width:100px;height:20px;"/>
    </div>
    </form>


  public class Get_02Ajax : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            string moneyType = context.Request["moneyType"];
            int account = Convert.ToInt32(context.Request["account"]);
          
            DataTable dt = SQLHelper.GetDataTable(" Select * from  Fruits ");
            string strResult = JsonConvert.SerializeObject(dt,Formatting.Indented);
            string strNone = JsonConvert.SerializeObject(dt,Formatting.None);
            switch (moneyType)
            {
                case "1":
                    context.Response.Write(account / 0.33);
                    break;
                case "2":
                    context.Response.Write(account * 10);
                    break;
                case "3":
                    context.Response.Write(account * 15);
                    break;
            }
            //context.Response.Write(strResult);  
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值