getParameter方法获取内容是为null的一个原因send(没加=号)

        //post
        document.getElementById("btn2").onclick = function () {
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function () {
                if (this.readyState == 4) {
                    if (this.status == 200) {
                        document.getElementById("mydiv").innerHTML = this.responseText

                    } else {
                        alert(this.status)
                    }
                }
            }
            xhr.open("POST", "/ajax/ajaxrequest8", true)
            xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
            var username = document.getElementById("username").value;
            xhr.send("username" + username)

send("username" + username)需要=号满足JSON格式,由于是“  ”中字符串问题,难以发现

添加=号为send("username=" + username)解决问题

猜你喜欢

转载自blog.csdn.net/m0_70984835/article/details/129827225