<script src="JQuery.js"></script>
<script>
// 拿到a的数据后才去请求b,拿到b的数据后再去请求c 这就叫回调地狱
// 像这种回调嵌套回调的写法就叫回调地狱
// $.ajax({
// method: "get",
// url: "data.json",
// success(res) {
// console.log(res);
// $.ajax({
// method: "get",
// url: "data2.json",
// success(res) {
// console.log(res);
// $.ajax({
// method: "get",
// url: "data3.json",
// success(res) {
// console.log(res);
// },
// });
// },
// });
// },
// });
//jq的ajax本身就是一个promise对象
$.ajax({
method: "get",
url: "data.json",
})
.then((res) => {
console.log(res);
return $.ajax({
method: "get",
url: "data2.json",
});
})
.then((res) => {
console.log(res);
return $.ajax({
method: "get",
url: "data3.json",
});
})
.then((res) => {
console.log(res);
console.log("最终拿到的", res);
});
//用promise 的方法处理回调地狱
</script>