function CheckValidateCode()
{
obj = document.all["tbValidCode"].value;
response = CompanyReg.GetValidateCode(obj);
if(response.value != "sucess")
{
//alert(response.value);
//document.all["tbValidCode"].focus();
SetSpan("spValiateCode","验证码错误");
return false;
}
SetSpan("spValiateCode","");
return true;
}
Ajax.Utility.RegisterTypeForAjax(typeof(PageClass));
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
public string GetValidateCode(string strValue)
{
string result = "";
try
{
if (System.Web.HttpContext.Current.Session["CheckCode"].ToString() == strValue.Trim().ToUpper())
{
result = "sucess";
}
else
{
result = "fail";
}
return result;
}
catch
{
return "fail";
}
}
本文介绍了一种使用Ajax实现的验证码校验方法。该方法通过客户端JavaScript进行初步验证,并利用Ajax异步请求与服务器端交互,确认用户输入的验证码是否正确。文章提供了完整的代码示例,包括前端验证函数和后端验证逻辑。
2333

被折叠的 条评论
为什么被折叠?



