代码:
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>ajax无刷新验证</title> </head> <body> <h2>用户登录</h2> <form> <p>用户:<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(){ // console.log('tt') $.ajax({ //请求的服务器资源,必须是字符串 url: 'api/demo.php', type: 'GET', data: $('form:first ').serializeArray(), //成功回调 success: function(msg,status,xhr) { console.log(msg) $('p span').empty() $('p').append($(msg)) } }) }) </script>
运行实例 »
点击 "运行实例" 按钮查看在线实例
手写代码: