加入web

This commit is contained in:
Raymond Yang
2023-07-10 15:36:47 +08:00
parent cd4d253c0c
commit 105391ae13
4 changed files with 76 additions and 59 deletions
+10 -9
View File
@@ -5,9 +5,10 @@
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>新增角色</title>
<script language="javascript" type="text/javascript">
<script>
const jwt = localStorage.getItem("jwtToken");
if (!jwt) {
window.location.href = "./login.html";
@@ -60,17 +61,17 @@
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
var selectElement = document.getElementById("character_index");
let selectElement = document.getElementById("character_index");
const name = ["前衛", "中衛", "後衛"];
for (var i = 0; i < name.length; i++) {
var optionElement = document.createElement("option");
for (let i = 0; i < name.length; i++) {
const optionElement = document.createElement("option");
optionElement.value = i;
optionElement.textContent = name[i];
selectElement.appendChild(optionElement);
}
var charaName = document.getElementById("character_name");
var charaPos = document.getElementById("character_position");
const charaName = document.getElementById("character_name");
const charaPos = document.getElementById("character_position");
// 监听表单提交事件
document.getElementById('upload-form').addEventListener('submit', async (event) => {
@@ -92,12 +93,12 @@
return;
}
var data = {
let data = {
name: charaName.value,
position: selectElement.value,
standIndex: parseInt(charaPos.value)
};
var jsonString = JSON.stringify(data);
let jsonString = JSON.stringify(data);
console.log(jsonString); // 处理上传成功的响应
try {
@@ -107,7 +108,7 @@
formData.append('image', imageFile);
// 发送 POST 请求
const response = await axios.post('http://127.0.0.1:8080/api/v1/character', formData, {
const response = await axios.post('./api/v1/character', formData, {
headers: {
'Authorization': 'Bearer ' + jwt, // 替换为实际的 JWT Token
'Content-Type': 'multipart/form-data',