AJAX登入集成CAS的项目获取用户信息

该博客演示了一个使用AJAX与CAS(Central Authentication Service)集成的项目,通过AJAX调用来获取用户信息。页面加载时,首先获取CAS登录所需的LT(Ticket Granting Ticket),然后进行登录操作,最后获取并显示用户信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<pre name="code" class="html"><!doctype html>
<html>
 <head>
  <title>获取与CAS集成项目的用户信息</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta content="telephone=no" name="format-detection">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="#ffffff" name="msapplication-TileColor">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
	
 </head>

 <body>
	
	<div>hello</div>
	<script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
	<script type="text/javascript">
	
	var username="11";
	var password="111";
	var ctx="http://chenyongtu.gicp.net";
	var ctx_t=ctx+"/teenagers";
	var ctx_c=ctx+"/cas";
	var url_userinfo=ctx+"/teenagers/a/mobile/userInfoNew?mobileLogin=true"
	var _services="service="+ encodeURIComponent(ctx_t+"/a/myTest/testLogin");
	var casUrl=ctx_c+"/login?"+_services+"&get-lt=true&n="+new Date().getTime();
	
		
	$(document).ready( function(){	
		 
		 //getuserinfo(url_userinfo);
		getTL(casUrl);
		

	});
	
	function getTL(url){
	$.ajax({   
		url:url,   
		type:'get',   
		data:'',  
		async : false,   
		error:function(){   
		   alert('error');   
		},   
		success:function(result){   
			console.log(result);
			var data="lt="+result.split("&")[0]+"&execution="+result.split("&")[1].replace("/\r\n/g", "").replace("/\n/g", "")+"&_eventId=submit&username="+username+"&password="+password+"&submit=%E7%99%BB%E5%BD%95";
			var services="service="+encodeURIComponent(ctx_t+"/a/cas");
			
			var url=ctx_c+"/login?"+services+"&"+data;
			console.log("url"+url);
			
			login(url);
			
		}
	});
}


function login(url){
	$.ajax({   
		url:url,   
		type:'post',   
		data:'',  
		async : false,   
		error:function(){   
		   alert('error');   
		},   
		success:function(data){   
		   console.log(data);   
		   getuserinfo(url_userinfo);
		}
	});
}

function getuserinfo(url){

	$.get(url, function(data){
		console.log(data); 
	});

}

	</script>	 		
 </body>
</html>



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值