documentgetElementByIdblogFormaddEventListenersubmit e = var title = documentgetElementsByNametitle0value; var author = documentgetElementsByNameauthor0value; var cla
document.getElementById("blogForm").addEventListener("submit", (e) => { e.preventDefault(); // prevent the form from submitting
var title = document.getElementsByName("title")[0].value;
var author = document.getElementsByName("author")[0].value;
var classify = document.getElementsByName("classify")[0].value;
axios({
url: "http://localhost:3000/api/blogs/add",
method: "post",
data: {
title,
author,
classify
}
}).then(result => {
alert("新增文章成功");
window.location.href = "index.html"; // redirect to index.html
}).catch(error => {
console.log(error);
console.log(error.response.data.message);
alert("新增文章失败");
})
})
原文地址: https://www.cveoy.top/t/topic/h2Gz 著作权归作者所有。请勿转载和采集!