<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Axios POST Request</title>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<button id="postButton">Send POST Request</button>
<script>
document
.getElementById('postButton')
.addEventListener('click', function () {
axios
.post('', {
password: '',
username: ''
})
.then(function (response) {
console.log(response.data)
alert(`successful==>>【${response.data.data}】`)
})
.catch(function (error) {
console.error('There was an error!', error)
alert('POST request failed!')
})
})
</script>
</body>
</html>
html中使用原生js发起axios请求
最新推荐文章于 2024-12-02 12:32:37 发布