Skip to content

Instantly share code, notes, and snippets.

@0xlitf
Created December 27, 2016 07:04
Show Gist options
  • Select an option

  • Save 0xlitf/106980e1de959a6620913367ab72842f to your computer and use it in GitHub Desktop.

Select an option

Save 0xlitf/106980e1de959a6620913367ab72842f to your computer and use it in GitHub Desktop.
XMLHttpRequest
var http = new XMLHttpRequest()
var url = "http://127.0.0.1:8080/hangzhoubaogongdian/findUser.do?";
var params = "usernameSch=" + user + "&passwordSch=" + password;
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {
if (http.readyState == 4) {
if (http.status == 200) {
console.log("ok: " + http.responseText)
var responseMsg = JSON.parse(http.responseText)["responseMsg"]
if (responseMsg === "用户名或密码错误"){
notification.show("用户名或密码错误");
}
else if (responseMsg === "操作成功"){
loginAccess()
}
} else {
console.log("error: " + http.status + " " + http.responseText)
notification.show("无法连接");
}
}
}
console.log(params)
http.send(params);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment