You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

61 lines
1.6 KiB

  1. function GetPageurl()
  2. {
  3. var url=window.location.href;//获取完整URL地址
  4. var tmp= new Array();//临时变量,用于保存分割字符串
  5. tmp=url.split("/");//按照"/"分割
  6. var cc = tmp[tmp.length-1];//获取最后一部分,即文件名和参数
  7. tmp=cc.split("?");//把参数和文件名分割开
  8. return tmp[0];//返回值
  9. }
  10. function getQueryString(name) {
  11. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  12. var r = window.location.search.substr(1).match(reg);
  13. if (r != null) return unescape(r[2]); return '';
  14. }
  15. function checkLogin(){
  16. xm_data=$.cookie('xm_data');
  17. if(xm_data ==undefined){
  18. alert('未登录的用户请先登录!');
  19. var refresh=encodeURI(window.location.href);
  20. window.location.href='./login.html?refresh='+refresh;
  21. return false;
  22. }else{
  23. return true;
  24. }
  25. }
  26. function checkAuth(){
  27. var curWwwPath=window.location.href;
  28. var pathname= window.location.pathname;
  29. var pos=curWwwPath.indexOf(pathname);
  30. var localhostPaht=curWwwPath.substring(0,pos);
  31. $.ajax({
  32. async: false,
  33. type:'post',
  34. dataType: "json",
  35. data:{method:'checkAuth',data:xm_data,pathname:pathname},
  36. url : localhostPaht+'/st-xm/Api/login.php',
  37. success : function(data) {
  38. if(data.errcode ==0){
  39. result=true;
  40. }else if(data.errcode ==1){
  41. alert(data.errinfo);
  42. window.location.href="./hello.html";
  43. result=false;
  44. }else if(data.errcode==2){
  45. alert(data.errinfo+'123');
  46. window.location.href="./login.html";
  47. result=false;
  48. }
  49. },
  50. error : function() {
  51. alert('fail');
  52. result=false;
  53. }
  54. });
  55. return result;
  56. }
  57. function login(){
  58. if(checkLogin()){
  59. checkAuth();
  60. }
  61. }