使用axios来发送ajax》get请求

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<!-- 引入axios库 -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<script type="text/javascript">
// axios.get axios发送get请求
// const常量 res1为Promise对象,axios可执行异步请求,发送请求的时候
// res1对象生成参数,请求又响应后,可用res1 去获取响应。
const res1 = axios.get('http://127.0.0.1:5000/api/projects')
console.log(res1)
// 用res1调用then函数去获取响应对象。
res1.then(function(response){
console.log('res1:',response)
})
const res2 = axios.get('http://127.0.0.1:5000/api/projects')
console.log(res2)
res2.then(function(response){
console.log('res2:',response)
})

console.log('python')
</script>
</body>
</html>

posted @ 2022-10-17 15:14  努力奋进  阅读(176)  评论(0编辑  收藏  举报