jq的get,post请求的演示

jq的get,post请求的演示

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <h1>标题</h1>
  <h2>名称</h2>
  <h3>皮肤</h3>

  <script src="./lib/jquery.min.js"></script>
  <script>
  
  
    $(function () {

      // 1 使用jq的 get请求 来请求数据
      // 2 一定要确认 接口地址 没有写错  
      //    验证的方式  把请求 放在浏览器内 访问 如何有数据 表示没有问题!!  
      // http://127.0.0.1:3001/getHero

      $.get(
        "http://127.0.0.1:3001/getHero",
        function (res) {
          // 回调函数 会在 数据响应回来了 触发
          console.log(res);

          $("h1").text(res.data.title);
          $("h2").text(res.data.cname);
          $("h3").text(res.data.skin_name);

        }
      )


    })
$("#heroSubmit").click(function () {
        // 英雄的名称
        const name = $("#name").val().trim();
        // 英雄的性别
        const gender = $("#gender").val();
        // 英雄的头像 先写死 空字符串 
        const img = "";

        // 发送给后台 完成添加 
        // url
        // 请求方式
        // 参数 

        $.post("http://127.0.0.1:3001/addHero", { name, gender, img }, 		    function (res) {
          console.log(res);
        })
  </script>
</body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值