发表于: 2019-12-15 14:35:21
1 964
今日完成:
$(function () {
$('#log_btn').on('click', function () {
var name = $('#username').val();
var pwd = $('#password').val();
console.log("name:" + name);
console.log("psd:" + pwd);
var data = "name=" + name + "&&pwd=" + pwd;
var a=log(data);
console.log(a);
});
function log(user) {
var code = 0;
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState === 4 && xhr.status === 200) {
code = JSON.parse(this.response).code;
console.log(code);
switch (code) {
case 200:
alert("登陆成功!");
// window.location.href='';
break;
case -100:
alert("密码错误");
break;
case -200:
alert("用户不存在");
}
} else {
console.log(xhr.responseText);
}
};
var url1='http://119.10.57.69:880/carrots-admin-ajax/a/login';
var url = 'http://localhost:8080/log';
xhr.open('post', url, true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.send(user);
return code;
}
});
那个学员接口用postman还是调不通,只能用自己的接口了。
直接调用本地接口的没啥问题,远程服务器上接口没部署好,远程数据库还有点问题。
评论