代码
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>3.$.ajax()</title> </head> <body> <h2>用户登录</h2> <form id="form"> <p id="ptext">用户名:<input type="text" name="name"></p> </form> </body> </html> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript"> $(':input').blur(function(){ $.ajax({ url: 'data.php', data: $('#form').serialize(), success: function(msg){ $('span').empty() $('#ptext').append(msg) } }) }) </script>