function Login(){
var name = $("#txt_loginname").val();
var pwd = $("#txt_pwd").val();
if(name == '') {
$("#login_msg").html("请输入用户名");
return;
}
if(pwd == '') {
$("#login_msg").html("请输入密码");
return;
}
try
{
$.ajax({
url: '/ws/UserService.asmx/Login',
data: '{loginName:"' + name + '",password:"' + pwd +'"}',
type: 'post',
dataType: 'json',
contentType: 'application/json; charset=utf8',
cache: false,
success: function(data) {
if (data.d == '1') {
ShowLogined();
}
else if(data.d == '0'){
$("#login_msg").html("用户名或密码错误");
}
else{
ToLoginPage();
}
},
error: function(xhr) {
alert(xhr.responseText);
}
});
}
catch(e){
//alert(e);
}
}
function ToRegPage(){
window.location.href="http://passport.cnblogs.com/register.aspx";
}
function ShowLogin(){
var str = "
用户名:"+
" 密码:"+
" "+
"
";
if(!document.getElementById("user_block"))
{
alert('不存在');
}
else
{
$("#user_block").html(str);
}
}
function ToLoginPage(){
window.location.href="http://passport.cnblogs.com/login.aspx?fail=1&ReturnUrl=http://dotnet.cnblogs.com/scriptLogin.aspx";
}
function ShowLogined(){
$.ajax({
url: '/ws/UserService.asmx/GetDisplayName',
data: '{}',
type: 'post',
dataType: 'json',
contentType: 'application/json; charset=utf8',
cache: false,
success: function(data) {
if (data.d) {
ShowLoginedInfo(data.d);
}
else{
document.write("登录失败");
}
},
error: function(xhr) {
if(xht.responseText != '')
{
alert(xhr.responseText);
}
}
});
}
function Logout(){
$.ajax({
url: '/ws/UserService.asmx/Logout',
data: '{}',
type: 'post',
dataType: 'json',
contentType: 'application/json; charset=utf8',
success: function(data) {
ShowLogin();
},
error: function(xhr) {
alert(xhr.responseText);
}
});
}
function ShowLoginedInfo(displayName)
{
var str = "";
if(!document.getElementById("user_block"))
{
alert('不存在');
}
else
{
$("#user_block").html(str);
}
}
ShowLogin();