CustomValidator控件+ajax 实现注册时的异步验证
在.net的验证控件中有一个CustomValidator验证控件,其属性ClientValidationFunction为客户端函数,在需要验证的控件失去焦点或者post数据时,调用该函数。
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomValidatorTest.aspx.cs" Inherits="Web.CustomValidatorTest" %>
<!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 runat="server">
<title></title>
<mce:script type="text/javascript" src="jquery/jquery-1.2.6-vsdoc-cn.js" mce_src="jquery/jquery-1.2.6-vsdoc-cn.js"></mce:script><%--jquery文件--%>
<mce:script type="text/javascript"><!--
function validator(oSrc, args) {
//oSrc 为object 类型,为CustomValidator1对象
//args为有两个属性:Value为验证控件的值,
// IsValid 为bool类型,表示是否验证通过
$.ajax({
async: false, //同步,异步不行,在ajax为返回之前,函数就结束,提交IsValid的值了。
type: "POST",
url: "CustomValidatorTestHander.ashx",
data: "val=" + args.Value,
success: function(msg) {
if (msg == "123") {
//如果后台返回值为123,验证失败
args.IsValid = false;
//todo
//这里是否可以修改oSrc对象来实现异步请求呢?
}
}
});
}
// --></mce:script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>输入123验证失败:</td>
<td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
<td><asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="验证不通过"
相关文档:
function selectTradezone(){
var copyTradezone = document.forms[0].copyTradezone;
new BaseTool().ajax("getTradezoneByCity",callback,[document.forms[0].city.value,document.forms[0].brand.value]);
function callba ......
Ajax 给 XMLHttpReq.onreadystatechange传递参数
通过:
xmlhttp.onreadystatechange= function(){xx(123)};
or
xmlhttp.onreadystatechange= new Function("xx(123)");
就可以了。
m=document.getElementsByName("text8");
v=m[i];
XMLHttpReq.onreadystatechange=function(){proce(v)};
---------------------- ......
<script type="text/javascript">
function addUrl(){
//1、设置请求url地址
var name = document.getElementById("name").value;
var text = document.getElementById("url").value;
var url = "insertUrl.do?name="+name+
"&url="+text+"&time"+new Date() ;
//2、创建xmlHttpRequest对象
x ......
一.摘要
本系列文章将带您进入jQuery的精彩世界, 其中有很多作者具体的使用经验和解决方案,
即使你会使用jQuery也能在阅读中发现些许秘籍.
本篇文章讲解如何使用jQuery方便快捷的实现Ajax功能.统一所有开发人员
使用Ajax的方式.
二.前言
Ajax让用户页面丰富起来, 增强了用户体验.
使用Ajax是所有Web开发的必 ......
XMLHttpRequest对象是Ajax的核心,它有许多属性,方法和事件以便于脚本的处理和控制HTTP的请求与响应
下面是关于XMLHttpRequest对象的一些属性和方法介绍
1.readyState属性
当XMLHttpRequest对象被创建后,readyState属性标识了当前对象所处的状态,具体的值代表意义如下:
0 未初始化状态, ......