ajax无法通过location.href跳转到指定页面

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 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>

这是绑定事件的按钮


type="button" id="btn"  value="提交"> 

确定一下if (resp.data=="true"){返回的是不是字符串true

绑定事件的按钮


<input type="button" id="btn"  value="提交"> 

使用
windows.open("http://localhost:8080/brand-demo/brand.html");
试试