//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)解决问题