当前位置: 首页 > news >正文

Ajax

一、什么是Ajax

<!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>原生Ajax</title>
</head>
<body><input type="button" value="获取数据" onclick="getData()"><div id="div1"></div></body>
<script>function getData(){//1. 创建XMLHttpRequest var xmlHttpRequest  = new XMLHttpRequest();//2. 发送异步请求xmlHttpRequest.open('GET','http://yapi.smart-xwork.cn/mock/169327/emp/list');xmlHttpRequest.send();//发送请求//3. 获取服务响应数据xmlHttpRequest.onreadystatechange = function(){if(xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200){document.getElementById('div1').innerHTML = xmlHttpRequest.responseText;}}}
</script>
</html>

二、Axios

<!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>Ajax-Axios</title><script src="js/axios-0.18.0.js"></script>
</head>
<body><input type="button" value="获取数据GET" onclick="get()"><input type="button" value="删除数据POST" onclick="post()"></body>
<script>function get(){//通过axios发送异步请求-get// axios({//     method: "get",//     url: "http://yapi.smart-xwork.cn/mock/169327/emp/list"// }).then(result => {//     console.log(result.data);// })axios.get("http://yapi.smart-xwork.cn/mock/169327/emp/list").then(result => {console.log(result.data);})}function post(){//通过axios发送异步请求-post// axios({//     method: "post",//     url: "http://yapi.smart-xwork.cn/mock/169327/emp/deleteById",//     data: "id=1"// }).then(result => {//     console.log(result.data);// })axios.post("http://yapi.smart-xwork.cn/mock/169327/emp/deleteById","id=1").then(result => {console.log(result.data);})}
</script>
</html>

http://www.lryc.cn/news/182135.html

相关文章:

  • SQL_ERROR_INFO: “Duplicate entry ‘9003‘ for key ‘examination_info.exam_id‘“
  • 解决每次重启ganache虚拟环境,十个账号秘钥都会改变问题
  • sheng的学习笔记-【中文】【吴恩达课后测验】Course 2 - 改善深层神经网络 - 第一周测验
  • (粗糙的笔记)动态规划
  • Kaggle - LLM Science Exam上:赛事概述、数据收集、BERT Baseline
  • 数据分析三剑客之一:Numpy详解及实战
  • 【C语言】函数的定义、传参与调用(二)
  • Sentinel安装
  • 【JVM】并发可达性分析-三色标记算法
  • 黑豹程序员-架构师学习路线图-百科:Git/Gitee(版本控制)
  • 《Jetpack Compose从入门到实战》第一章 全新的 Android UI 框架
  • 基于Spring Boot的中小型医院网站的设计与实现
  • uniapp iOS离线打包——如何创建App并提交版本审核?
  • 论文笔记:Contrastive Trajectory Similarity Learning withDual-Feature Attention
  • 整数和字符串比较的坑
  • LeetCode 面试题 08.04. 幂集
  • 【m_listCtrl !=NULL有多个运算符与操作数匹配】2023/9/21 上午11:03:44
  • Logrus 集成 color 库实现自定义日志颜色输出字符原理
  • 【Java-LangChain:使用 ChatGPT API 搭建系统-2】语言模型,提问范式与 Token
  • 想要精通算法和SQL的成长之路 - 最长连续序列
  • UG NX二次开发(C#)- 制图(Draft)-工程图框选制图曲线并输出制图曲线的信息
  • 1.7.C++项目:仿muduo库实现并发服务器之Poller模块的设计
  • Flutter笔记:build方法、构建上下文BuildContext解析
  • composer 安装和基本使用
  • Ubuntu配置深度学习环境(TensorFlow和PyTorch)
  • 【产品经理】国内企业服务SAAS平台的生存与发展
  • 【vue 首屏加载优化】
  • docker--redis容器部署及与SpringBoot整合-I
  • 力扣 -- 518. 零钱兑换 II(完全背包问题)
  • 一文搞懂UART通信协议