<div class="login-box"><div id="loginBox"> </div>
<script type="text/javascript">
var userToken;
$(function () {
$.ajax({
url: "http:(域名)/e/GetUserToken/",
type: "GET",
xhrFields: { withCredentials: true },
dataType: "json", //指定服务器返回的数据类型
success: function (data) {
if (data != "") {
var redirectUrl = encodeURIComponent(location.href);
var loginedHtml = '<a href="//(域名)/?redirectUrl=' + redirectUrl + '" class="denglu" target="_blank">登录</a><a href="//(域名)/Reg/?redirectUrl=' + redirectUrl + '" class="zhuce" target="_blank">注册</a>';
userToken = data.UserToken;
var currentUser = data.CurrentUser;
if (isNullOrEmpty(userToken) || isNullOrEmpty(currentUser)) {
$("#loginBox").html(loginedHtml);
return;
}
var nickName = data.NickName;
if (isNullOrEmpty(nickName)) {
nickName = currentUser.UserName;
}
nickName = nickName.left(10);
loginedHtml = '<a href="http://(域名)" class="denglu" title="进入会员中心" target="_blank">您好,' + nickName + '</a>';
$("#loginBox").html(loginedHtml);
}
}
});
});
</script></div>