无刷新网页表单使用
1、给表单添加验证
//注册验证 $("#myform").valid([ { name: "reg_name",type: "text",isNull: "用户不能为空",onFocus: "请填写用户!" },{ name: "reg_email",type: "mail",isNull: "邮箱不能为空",onFocus: "邮箱格式(*@*.*)",error: "邮箱格式不正确" },{ name: "reg_password",type: "password",isNull: "密码不能为空",onFocus: "请填写6-18位密码",error: "请填写6-18位密码" },{ name: "reg_confirm",type: "eq",error: "两次输入密码不一致",other: { to: "reg_password" } },{ name: "reg_code",type: "ajax",error: "验证码不正确",other: { url: "/Handlers/RegHandler.ashx" } } ],true);
2写入ajaxForm()
3、后台接受采用一般处理程序
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //如果用户直接访问handler则拒绝 if (context.Request.UrlReferrer == null) { context.Response.Write("请求错误!拒绝访问!"); return; } //获取请求来路的完整的url string url = context.Request.UrlReferrer.AbsoluteUri; if (!url.Contains("/CompanyDishes/DishesBooks")) { context.Response.Write("请求错误!拒绝访问"); return; } DishBook objBook = new Book() { CustomerName = context.Request.Params["CustomerName"],HotelName = context.Request.Params["HotelName"],ConsumeTime = Convert.ToDateTime(context.Request.Params["ConsumeTime"]),CustomerPhone = context.Request.Params["CustomerPhone"],CustomerEmail = context.Request.Params["CustomerEmail"],ConsumePersons = Convert.ToInt32(context.Request.Params["ConsumePersons"]),RoomType = context.Request.Params["selectRoomType"],Comments = context.Request.Params["Comments"] == "" ? "无" : context.Request.Params["Comments"],}; try { //提交数据 int count = new BookManager().AddBook(objBook); if (count > 0) context.Response.Write("success"); else { context.Response.Write("error"); } } catch (Exception ex) { context.Response.Write("提交失败!" + ex.Message); throw; } }