[PHP + AXIOS] Get / Post
페이지 정보
작성자 sbLAB 댓글 0건 조회 631회 작성일 23-07-09 19:21본문
axios/axios ★
https://github.com/axios/axios#cdn
AXIOS + GET request (params)
<head>
</head>
<body>
<div>
<input type="text" placeholder="토큰입력" id="tk" value="" size="70" />
</div>
<input type="button" onclick="onLoggin()" value="Request" />
<script>
let onLoggin = async function () {
const tk = document.getElementById('tk');
try {
// axios 요청 (get)
let res = await axios({
method: 'GET',
url: 'http://server_url/all',
params: {
tk: tk.value,
},
});
console.log(res);
console.log(res.data);
console.log(res.data[0]);
console.log(res.status);
document.getElementById('list_here').innerHTML = JSON.stringify(res);
//document.write(JSON.stringify(res));
} catch (err) {
console.log(err);
throw new Error(err);
}
};
</script>
</body>
<div id="list_here"></div>
AXIOS + POST request (data)
<head>
</head>
<body>
<div>
<input type="text" placeholder="토큰입력" id="tk" value="" size="70" />
</div>
<input type="button" onclick="onLoggin()" value="Request" />
<script>
let onLoggin = async function () {
const tk = document.getElementById('tk');
try {
// axios 요청 (post)
let res = await axios({
method: 'POST',
data: {
tk:'...........token value................'
},
});
console.log(res);
console.log(res.data);
console.log(res.data[0]);
console.log(res.status);
document.getElementById('list_here').innerHTML = JSON.stringify(res);
//document.write(JSON.stringify(res));
} catch (err) {
console.log(err);
throw new Error(err);
}
};
</script>
</body>
<div id="list_here"></div>
댓글목록
등록된 댓글이 없습니다.