这里是源代码:
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" xml:lang="en"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 5 <title>ajax2</title> 6 <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> 7 <script> 8 $(function(){ 9 $('input[type=button]').click(function() { 10 var url = 'process.php'; 11 var sendData = {'username':$('#username').val()}; 12 $.get(url,sendData,function(data){ 13 if(data=='true'){ 14 $('div').html('用户名可以注册'); 15 }else{ 16 $('div').html('用户名不能为admin'); 17 } 18 }); 19 }); 20 }); 21 </script> 22 <style> 23 div{color: red;} 24 </style> 25 </head> 26 <body> 27 <input type="text" name="username" id="username" /> 28 <input type="button" value="检验" /> 29 <div></div> 30 </body> 31 </html>
这是php代码:
1 <?php 2 header('Content-type:text/html;chartest=utf-8'); 3 // $username = $_POST['username']; 4 $username = $_GET['username']; 5 if($username=='admin'){ 6 echo 'false'; 7 }else{ 8 echo 'true'; 9 } 10 ?>