首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

异常: “CheckIsNullOld”未定义

2012-05-21 
错误: “CheckIsNullOld”未定义script typetext/javascript//判断浏览器,创建XMLHTTPRequest对象funct

错误: “CheckIsNullOld”未定义
<script type="text/javascript">
  //判断浏览器,创建XMLHTTPRequest对象
  function CreateXMLHTTPRequest(){
  if(window.ActiveXObject){
  return new ActiveXObject("Microsoft.XMLHTTP");
  }else{
  return new XMLHttpRequest();
  }
  }
  //检查旧密码框文本是否为空
 function CheckIsNullOld(){
  var str=document.getElementById("ctl00_ContentPlaceHolder1_txtOldPassword").value;
  if((str+"")==null||(str+"")==""){
  document.getElementById("oldPwd").innerText="不能为空";
  return false;
  }else {
  //1.创建XMLHTTPRequest对象
  var xmlHttpRequest=new XMLHttpRequest();
  window.Function(){
  xmlHttpRequest.onreadystatechange=readyDo;
  xmlHttpRequest.open("POST","~manage/AdminModifyHandler.ashx",true);
  xmlHttpRequest.setRequestHeader("Content_Type","application/x-www-form-urlencoded");
  var data="password="+str;
  xmlHttpRequest.send(data);
   
  }
  function readyDo(){
  if(xmlHttpRequest.readyState==4&&xmlHttpRequest.status==200){
  var result=xmlHttpRequest.responseText;
  if(result=="true"){
  document.getElementById("oldPwd").innerHTML="<img alt='' src='images/duihao.jpg'/>";
  }else {
  document.getElementById("oldPwd").innerText="密码错误~";
  return false;
  }
  }
  }  
 }


上面是javascript代码


下面是html代码:
  <tr>
  <td height="30" align="right">
  旧密码:
  </td>
  <td>
  <asp:TextBox ID="txtOldPassword" MaxLength="20" onblur="CheckIsNullOld()" TextMode="Password"
  runat="server"></asp:TextBox><span id="oldPwd" class="notice">*</span>
  </td>
  </tr>
  <tr>
  <td height="30" align="right">
  新新密码:
  </td>
  <td>
  <asp:TextBox ID="txtNewPassword" MaxLength="20" TextMode="Password" onblur="CheckIsNullNew()"
  runat="server" ValidationGroup="a"></asp:TextBox><span id="newPwd" class="notice">*</span>
  </td>
  </tr>
  <tr>
  <td height="30" align="right">
  确认新密码:
  </td>
  <td>
  <asp:TextBox ID="txtReNewPassword" MaxLength="20" TextMode="Password" onblur="CheckIsNullReNew()"
  runat="server" ValidationGroup="a"></asp:TextBox><span id="ReNewPwd" class="notice">*</span>
  <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtNewPassword"


  ControlToValidate="txtReNewPassword" ErrorMessage="两次密码不一致!" ValidationGroup="a"></asp:CompareValidator>
  </td>
  </tr>

下面是一般处理程序
public class AdminModifyHandler : IHttpHandler, IReadOnlySessionState
{

  public void ProcessRequest(HttpContext context)
  {
  context.Response.ContentType = "text/plain";
  string pwd = Md5(context.Request["password"]);
  if (pwd != null)
  {
  if (pwd == (context.Session["user"] as T_Manager).pwd)
  {
  context.Response.Write("true");
  }
  else
  {
  context.Response.Write("false");
  }
  }
   
  }

  public bool IsReusable
  {
  get
  {
  return false;
  }
  }

  /// <summary>
  /// MD5加密
  /// </summary>
  /// <param name="str"></param>
  /// <param name="code"></param>
  /// <returns></returns>
  public static string Md5(string str)
  {

  return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);


  }


各位朋友 帮看看 为啥鼠标onblur的时候错误: “CheckIsNullOld”未定义啊

[解决办法]

JScript code
 function CheckIsNullOld(){   var str=document.getElementById("ctl00_ContentPlaceHolder1_txtOldPassword").value;   if((str+"")==null||(str+"")==""){   document.getElementById("oldPwd").innerText="不能为空";   return false;   }else {   //1.创建XMLHTTPRequest对象   var xmlHttpRequest=new XMLHttpRequest();   window.function(){   xmlHttpRequest.onreadystatechange=readyDo;   xmlHttpRequest.open("POST","~manage/AdminModifyHandler.ashx",true);   xmlHttpRequest.setRequestHeader("Content_Type","application/x-www-form-urlencoded");   var data="password="+str;   xmlHttpRequest.send(data);       }   function readyDo(){   if(xmlHttpRequest.readyState==4&&xmlHttpRequest.status==200){   var result=xmlHttpRequest.responseText;   if(result=="true"){   document.getElementById("oldPwd").innerHTML="<img alt='' src='images/duihao.jpg'/>";   }else {   document.getElementById("oldPwd").innerText="密码错误~";   return false;   }   }   }    }} 

热点排行