bo-wen

 

HTML

 1 <button class="get">发送一个GET请求</button> 

 

jQuery

 1     $(".get").click(function () {
 2         // 使用 jquery 中的 ajax 发请求
 3         $.ajax({
 4             // 设置请求方法
 5             method: "GET",
 6             // 请求地址
 7             url: "/xhr",
 8 
 9             // 配置发送请求数据格式,默认 urlencoded 值 如若发送 formData 数据,属性改为 false
10             contentType: "application/x-www-form-urlencoded",
11 
12             // 请求数据
13         data: {
14                 username: "张三",
15                 age: "20",
16                 hobby: ["会唱", "会跳"],
17          },
18             // 配置接受数据格式 默认 json
19             dataType: "json",
20 
21             // 请求成功
22             success: function (res) {
23                 console.log(res);
24             }
25         })
26    })

 

 node 端

1 app.get("/xhr", function (req, res) {
2     res.json({
3         msg: "成功"
4     })
5 })

 

分类:

技术点:

相关文章:

  • 2021-11-23
  • 2021-06-02
  • 2021-11-23
  • 2021-11-23
  • 2022-12-23
  • 2021-12-21
  • 2022-01-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2021-11-23
  • 2021-11-23
相关资源
相似解决方案