1 Star 0 Fork 0

math.most/js_study

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
012.4promise.html 1.21 KB
一键复制 编辑 原始数据 按行查看 历史
math.most 提交于 2021-11-08 22:29 +08:00 . promise
<!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>Promise</title>
<script type="text/javascript" src="./jquery.min.js"></script>
</head>
<body>
<script>
function getData(url, data = {}) {
return new Promise((resolve, reject) => {
$.ajax({
type: "GET",
url: url,
data: data,
success: function (res) {
resolve(res)
},
error: function (error) {
reject(error)
}
})
})
}
// 调用函数
getData('data1.json')
.then((data) => {
const { id } = data;
return getData('data2.json', { id })
})
.then((data) => {
const { username } = data;
return getData('data3.json', { username })
})
.then((data) => {
console.log(data);
})
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mathmost/js_study.git
git@gitee.com:mathmost/js_study.git
mathmost
js_study
js_study
master

搜索帮助