第一个ajax程序 get/post

1.html文件 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/jquery-1.12.4.min.js"></script>
    <script>
        // 方法一
        // $.ajax({
        //     "url":"data.json",
        //     "type":"GET",
        //     "dataType":"JSON",
        //     success:function(data){
        //         alert(data.name)
                
        //     },

        //     error:function(){
        //         alert("error")

        //     },
        //     async:true
        // });

        // 方法二
        // 1.请求的地址
        // 2.请求传给web服务器的参数
        // 3.请求成功的回调函数
        // 4.返回数据的解析方式
        // 5.error失败执行的回调函数
        // $.get("data.json",{"name":"ls"},function(data){
        //     console.log(data.name)

        // },"JSON").error(function(){
        //     alert("失败")
        // });
 

        // post请求
        $.post("data.json",{"name":"ls"},function(data){
            console.log(data.name)

        },"JSON").error(function(){
            alert("失败")
        });
    </script>
</head>
<body>
    
</body>
</html>

2.data.json

{"name": "bob"}

3.run http server:

https://blog.csdn.net/CherryChanccc/article/details/135834540?spm=1001.2014.3001.5502

4.

相关推荐

  1. 第一Rust程序

    2024-02-05 15:12:08       27 阅读
  2. 开发第一SpringBoot程序

    2024-02-05 15:12:08       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-05 15:12:08       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-05 15:12:08       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-05 15:12:08       82 阅读
  4. Python语言-面向对象

    2024-02-05 15:12:08       91 阅读

热门阅读

  1. PyTorch、NCNN、CV::Mat三者张量的shape

    2024-02-05 15:12:08       41 阅读
  2. createvm

    2024-02-05 15:12:08       47 阅读
  3. rust ethers-rs 签名与solidity验证签名例子

    2024-02-05 15:12:08       44 阅读
  4. 力扣刷题-27.移除元素

    2024-02-05 15:12:08       51 阅读
  5. Ubuntu文件系统结构

    2024-02-05 15:12:08       54 阅读
  6. Rust个人学习之Rust国内镜像源

    2024-02-05 15:12:08       42 阅读
  7. 【MySQL】-10 MySQL 存储过程

    2024-02-05 15:12:08       38 阅读
  8. MySQL的存储过程

    2024-02-05 15:12:08       40 阅读
  9. mysql 删除分区表数据

    2024-02-05 15:12:08       48 阅读
  10. MVVM下的窗口关闭

    2024-02-05 15:12:08       51 阅读
  11. ChatGPT高效提问—基础知识(NLP)

    2024-02-05 15:12:08       49 阅读