Promise-nesting
<!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="../utils.js"></script>
</head>
<body>
<button onclick="sendMsg()">发送请求</button>
<script>
function sendMsg () {
utils.fetch('./06.php', {
id: prompt() }).then(resp => {
console.log(resp)
return utils.fetch('./06.php', {
id: prompt() })
}).then(resp1 => {
console.log(resp1)
return utils.fetch('./06.php', {
id: prompt() })
}).then(resp2 => {
console.log(resp2)
}).catch(() => {
console.log('只要由任意一个promise走了reject,这里就会执行')
})
}
</script>
<