日期:2014-05-16 浏览次数:20630 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>无标题页</title> <script src="js/jquery-1.4.2.js" type="text/javascript"></script> <script type="text/javascript"> function Button1_onclick(){ var amount = $("#Text1").val(); var moneytype = $("#Select1").val(); var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); //创建XMLHTTP对象 if(!xmlhttp){ alert("创建xmlhttp对象异常!"); return false; } xmlhttp.open("POST","HuiLv1.ashx?amount="+amount+"&moneytype="+moneytype+"&ts="+new Date(),false); xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ if(xmlhttp.status == 200){ //如果状态吗是200则代表成功。 $("#Text2").val(xmlhttp.responseText); } else { alert("ajax服务器返回错误"); } } } xmlhttp.send(); } </script> </head> <body> <input id="Text1" type="text" /> <select id="Select1" name="D1"> <option value="1">美元</option> <option value="2">日元</option> <option value="3">港币</option> </select> <input id="Button1" type="button" value="button" /><input id="Text2" type="text" /> </body> </html>
using System; using System.Collections; using System.Data; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml.Linq; namespace AJAX测试1 { /// <summary> /// $codebehindclassname$ 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class HuiLv1 : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string amount = context.Request["amount"]; int iAmount = Convert.ToInt32(amount); string moneytype = context.Request["moneytype"]; if (moneytype == "1") //美元 { context.Response.Write(iAmount / 7); } else if (moneytype == "2") //日元 { context.Response.Write(iAmount * 10); } else if (moneytype == "3") //港币 { context.Response.Write(iAmount * 10 / 9); } else { } } public bool IsReusable { get { return false; } } } }