ajax无法通过location.href跳转到指定页面
<script>
document.getElementById("btn").onclick=function () {
let formdata={
brandName:"",
companyName:"",
ordered:"",
description:"",
status:""
}
let brandName = document.getElementById("brandName").value;
formdata.brandName=brandName;
formdata.companyName=document.getElementById("companyName").value;
formdata.ordered=document.getElementById("ordered").value;
formdata.description=document.getElementById("description").value;
let num = document.getElementsByName("status");
for (let i = 0; i <num.length; i++) {
if (num[i].checked){
formdata.status=num[i].value;
}
}
axios({
method:"post",
url:"http://localhost:8080/brand-demo/addServlet",
data:formdata
}).then(function (resp){
if (resp.data=="true"){
window.location.href='http://localhost:8080/brand-demo/brand.html';
}
})
}
</script>
这是绑定事件的按钮
<input value="提交" id="btn" type="button" />