Correction status:qualified
Teacher's comments:
<!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(){ //alert('通过') $.ajax({ //请求服务器资源,必须是字符串 url:'api/demo.php', //客户端请求类型:get,post type:'GET' //重服务器端返回数据类型格式, dataType:'json', //异步true 还是同步false async:true, //发送数据 data:'name='+$(':input').val(), data:$('form:first').serialize(), //成功回调 success:function(){ console.log(msg) $('p span').empty() $('p').append($(msg)) } }) }) </script>
点击 "运行实例" 按钮查看在线实例