批改状态:合格
老师批语:
<!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>点击 "运行实例" 按钮查看在线实例


Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号