Created
December 27, 2016 07:04
-
-
Save 0xlitf/106980e1de959a6620913367ab72842f to your computer and use it in GitHub Desktop.
XMLHttpRequest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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