1. loginIn() 改用 ci_admin 表验证(原查 ci_staff 表 passWord 字段不存在) 2. login() cookie自动登录同步修复 3. good() 页面增加登录态验证 4. login.php 表单 action 修正为 mobile/loginIn 5. login.js 修复 JSON 解析问题(responseType=json 在原生XHR无效) 6. 登录成功返回完整URL跳转地址
137 lines
3.8 KiB
JavaScript
Executable File
137 lines
3.8 KiB
JavaScript
Executable File
window.onload=function(){
|
|
var aInput=document.getElementsByTagName('input');
|
|
var oUser=aInput[0];
|
|
var oPwd=aInput[1]
|
|
var aI=document.getElementsByTagName('i')[0];
|
|
var sub = document.getElementById("submit");
|
|
sub.onclick = function(){
|
|
if(oUser.value==""){
|
|
aI.innerHTML='账号不可为空';
|
|
return false;
|
|
}
|
|
if(oPwd.value==""){
|
|
aI.innerHTML='密码不可为空';
|
|
return false;
|
|
}
|
|
ajax({
|
|
type:"POST",
|
|
url:"loginIn",
|
|
dataType:"json",
|
|
data:{user:oUser.value,pwd:oPwd.value},
|
|
beforeSend:function(){
|
|
//some js code
|
|
},
|
|
success:function(rtn){
|
|
if(rtn.code != '200' && rtn.code != 200)
|
|
aI.innerHTML= rtn.msg;
|
|
else
|
|
location.href = rtn.msg;
|
|
},
|
|
error:function(){
|
|
console.log("error")
|
|
}
|
|
})
|
|
|
|
return false;
|
|
}
|
|
|
|
oUser.onfocus=function(){
|
|
aI.innerHTML='';
|
|
oUser.removeAttribute("placeholder");
|
|
}
|
|
|
|
oUser.onkeyup=function(){}
|
|
|
|
oUser.onblur=function(){
|
|
if(oUser.value==""){
|
|
oUser.setAttribute("placeholder","账号不可为空");
|
|
}
|
|
}
|
|
|
|
oPwd.onfocus=function(){
|
|
oPwd.removeAttribute("placeholder");
|
|
}
|
|
oPwd.onblur=function(){
|
|
if(oPwd.value==""){
|
|
oPwd.setAttribute("placeholder","请输入确认密码");
|
|
}
|
|
}
|
|
}
|
|
|
|
var Ajax={
|
|
get: function(url, fn) {
|
|
var obj = new XMLHttpRequest();
|
|
obj.open('GET', url, true);
|
|
obj.onreadystatechange = function() {
|
|
if (obj.readyState == 4 && (obj.status == 200 || obj.status == 304)) {
|
|
fn.call(this, obj.responseText);
|
|
}
|
|
};
|
|
obj.send();
|
|
},
|
|
post: function (url, data, fn) {
|
|
var obj = new XMLHttpRequest();
|
|
obj.open("POST", url, true);
|
|
obj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
|
obj.onreadystatechange = function() {
|
|
if (obj.readyState == 4 && (obj.status == 200 || obj.status == 304)) {
|
|
fn.call(this, obj.responseText);
|
|
}
|
|
};
|
|
obj.send(data);
|
|
}
|
|
}
|
|
|
|
function ajax(){
|
|
var ajaxData = {
|
|
type:arguments[0].type || "GET",
|
|
url:arguments[0].url || "",
|
|
async:arguments[0].async || "true",
|
|
data:arguments[0].data || null,
|
|
dataType:arguments[0].dataType || "text",
|
|
contentType:arguments[0].contentType || "application/x-www-form-urlencoded",
|
|
beforeSend:arguments[0].beforeSend || function(){},
|
|
success:arguments[0].success || function(){},
|
|
error:arguments[0].error || function(){}
|
|
}
|
|
ajaxData.beforeSend()
|
|
var xhr = createxmlHttpRequest();
|
|
xhr.open(ajaxData.type,ajaxData.url,ajaxData.async);
|
|
xhr.setRequestHeader("Content-Type",ajaxData.contentType);
|
|
xhr.send(convertData(ajaxData.data));
|
|
xhr.onreadystatechange = function() {
|
|
if (xhr.readyState == 4) {
|
|
if(xhr.status == 200){
|
|
var response = xhr.responseText;
|
|
if(ajaxData.dataType === "json" && response){
|
|
try { response = JSON.parse(response); } catch(e){}
|
|
}
|
|
ajaxData.success(response);
|
|
}else{
|
|
ajaxData.error()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function createxmlHttpRequest() {
|
|
if (window.ActiveXObject) {
|
|
return new ActiveXObject("Microsoft.XMLHTTP");
|
|
} else if (window.XMLHttpRequest) {
|
|
return new XMLHttpRequest();
|
|
}
|
|
}
|
|
|
|
function convertData(data){
|
|
if( typeof data === 'object' ){
|
|
var convertResult = "" ;
|
|
for(var c in data){
|
|
convertResult+= c + "=" + data[c] + "&";
|
|
}
|
|
convertResult=convertResult.substring(0,convertResult.length-1)
|
|
return convertResult;
|
|
}else{
|
|
return data;
|
|
}
|
|
}
|