-->html页

 

 

 

   1:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   2:  <html xmlns="http://www.w3.org/1999/xhtml">
   3:  <head>
   4:      <title>用户名校验实例</title>
   5:      <script src="../js/jquery-1.7.2.js" type="text/javascript"></script>
   6:      <script src="../js/verify.js" type="text/javascript"></script>
   7:  </head>
   8:  <body onload="verify()">
   9:  用户名校验的jax实例
  10:  <!--ajax方式下不需要使用表单进行数据提交,因此不用写表单-->
  11:  <input type="text" value="" id="userName" />&nbsp;
  12:  <input type="button" value="提交" onclick=""/>
  13:  <!--预留空间,显示结果-->
  14:  <div id="result"></div>
  15:  <!--div is block,but span is inline--->
  16:  </body>
  17:  </html>

—>js页

   1:  function verify() {
   2:      $("#userName").keyup(function () {
   3:          var user = $(this).val();
   4:          var userobj = $(this);
   5:          $.post("../index.aspx", { userobj: user }, callback);
   6:      });
   7:   
   8:  }
   9:  function callback(data) {
  10:      $("#result").text(data);
  11:  }

—>aspx页

   1:  <% 
   2:  Response.Clear();
   3:  string str_name = Request["userobj"];
   4:  if (str_name == "xtyang")
   5:  {
   6:   
   7:      Response.Write("ok");
   8:  }
   9:  else
  10:  {
  11:      Response.Write("no");
  12:  }
  13:  Response.End();      
  14:  %>