jq版的ajax

来源:互联网 发布:r语言数据可视化手册 编辑:程序博客网 时间:2024/04/28 23:20
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">

</style>
</head>
<body>
    <input type="text" name="name">
    <button>提交</button>
    <h1></h1>
</body>
<script  src="js/jquery-3.2.1.min.js" ></script>
<script type="text/javascript">
    $('button').on('click',function(){
       $.ajax({
  //后台地址
  url:'http://localhost/AJAX/php/jq.php',
  //请求方式
  type:'post',//method
  //向后台传递的数据
  data:{name:$('input').val()},
  //成功的回调函数 参数是后台传递过来的
  success:function(res){
          //alert(res);
          $('h1').html(res);
  },
  //是否异步,默认异步
  async:true
}); 


    });
 
</script>
</html>
原创粉丝点击