代码利用$.ajax实现了无刷新的实时在线验证
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>ajax</title> </head> <body> <form style="width: 450px"> <fieldset> <legend><h2>login</h2></legend> <p>name:<input type="text" name="name"></p> </fieldset> </form> </body> </html> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <script type="text/javascript"> $(':input').on('input',function(){ $.ajax({ url:'login.php', type :'POST', // dataType:'jsonp', async:'true', data:$('form:first').serializeArray(), success:function(msg,status,xhr){ // console.log(msg) $('p span').remove() $(msg).appendTo('p') } }) }) </script>
运行实例 »
点击 "运行实例" 按钮查看在线实例
总结:$.ajax(url,type,data,dataType,success,error) 请求加载远程数据