|
- function GetPageurl()
- {
- var url=window.location.href;//获取完整URL地址
- var tmp= new Array();//临时变量,用于保存分割字符串
- tmp=url.split("/");//按照"/"分割
- var cc = tmp[tmp.length-1];//获取最后一部分,即文件名和参数
- tmp=cc.split("?");//把参数和文件名分割开
- return tmp[0];//返回值
- }
- function getQueryString(name) {
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
- var r = window.location.search.substr(1).match(reg);
- if (r != null) return unescape(r[2]); return '';
- }
- function checkLogin(){
- var curWwwPath=window.location.href;
- var pathname= window.location.pathname;
- var pos=curWwwPath.indexOf(pathname);
- var localhostPaht=curWwwPath.substring(0,pos);
- xm_data=$.cookie('xm_data');
- if(xm_data ==undefined){
- var refresh=encodeURI(window.location.href);
- ZZAlertInfo('未登录的用户请先登录!',function(){
- window.location.href=localhostPaht+'/login.html?refresh='+refresh;
- },function(){
- window.location.href=localhostPaht+'/login.html?refresh='+refresh;
- },function(){
- window.location.href=localhostPaht+'/login.html?refresh='+refresh;
- });
- window.location.href=localhostPaht+'/login.html?refresh='+refresh;
- return false;
- }else{
- return true;
- }
- }
- function checkAuth(){
- var curWwwPath=window.location.href;
- var pathname= window.location.pathname;
- var pos=curWwwPath.indexOf(pathname);
- var localhostPaht=curWwwPath.substring(0,pos);
- $.ajax({
- async: false,
- type:'post',
- dataType: "json",
- data:{method:'checkAuth',data:xm_data,pathname:pathname},
- url : localhostPaht+'/st-xm/Api/login.php',
- success : function(data) {
- if(data.errcode ==0){
- result=true;
- }else if(data.errcode ==1){
- ZZAlertInfo(data.errinfo,function(){
- window.location.href=localhostPaht+"/hello.html";
- });
- result=false;
- }else if(data.errcode==2){
- ZZAlertInfo(data.errinfo,function(){
- window.location.href=localhostPaht+"/login.html";
- });
- result=false;
- }
- },
- error : function() {
- ZZAlertInfo('fail');
- result=false;
- }
- });
- return result;
- }
- function login(){
- if(checkLogin()){
- checkAuth();
- }
- }
|