Ajax.net中的Web服务
Login:用来登陆的方法
Sys.Services.AuthenticationService.login(username, password, isPersistent, redirectUrl, customInfo, loginCompletedCallback, failedCallback, userContext);
Logout:注销用户的方法
Sys.Services.AutenticationService.set_defaultLoginCompletedCallback(value);
var defaultLoginCompletedCallback = Sys.services.AuthenticationService.get_defaultLoginCompletedCallback();
Sys.Services.AuthenticationService.login(username, password, isPersistent, redirectUrl, customInfo, loginCompletedCallback, failedCallback, userContext);
Logout:注销用户的方法
Sys.Services.AutenticationService.set_defaultLoginCompletedCallback(value);
var defaultLoginCompletedCallback = Sys.services.AuthenticationService.get_defaultLoginCompletedCallback();
  1![]()
2![]() //登录按钮事件
//登录按钮事件
3![]() function OnClickLogin()
function OnClickLogin()
4![]() {
{
5![]() Sys.Services.AuthenticationService.login(
    Sys.Services.AuthenticationService.login(
6![]() document.form1.userId.value,
        document.form1.userId.value,
7![]() document.form1.userPwd.value,false,null,null,
        document.form1.userPwd.value,false,null,null,
8![]() OnLoginComplete, OnAuthenticationFailed,
        OnLoginComplete, OnAuthenticationFailed,
9![]() "User context information.");
        "User context information.");
10![]() }
}
11![]() // 注销按钮事件
// 注销按钮事件
12![]() function OnClickLogout()
function OnClickLogout()
13![]() {
{
14![]() Sys.Services.AuthenticationService.logout(
    Sys.Services.AuthenticationService.logout(
15![]() null, OnLogoutComplete, OnAuthenticationFailed,null);
        null, OnLogoutComplete, OnAuthenticationFailed,null);
16![]() }
}
17![]() //注销完成调用的方法
//注销完成调用的方法
18![]() function OnLogoutComplete(result,
function OnLogoutComplete(result, 
19![]() userContext, methodName)
    userContext, methodName)
20![]() {}
{}        
21![]()
22![]() //登录完成调用的方法
//登录完成调用的方法
23![]() function OnLoginComplete(validCredentials,
function OnLoginComplete(validCredentials, 
24![]() userContext, methodName)
    userContext, methodName)
25![]() {
{
26![]() //如果验证成功
//如果验证成功
27![]() if(validCredentials == true)
    if(validCredentials == true)
28![]() {
    {
29![]() DisplayInformation("欢迎你: " + document.form1.userId.value);//显示欢迎信息
        DisplayInformation("欢迎你: " + document.form1.userId.value);//显示欢迎信息
30![]() LoadProfile();//加载个性化配置
        LoadProfile();//加载个性化配置
31![]() // 隐藏不该显示的选择
        // 隐藏不该显示的选择
32![]() GetElementById("loginId").style.visibility = "hidden";
        GetElementById("loginId").style.visibility = "hidden";
33![]() GetElementById("setProfileProps").style.visibility = "visible";
        GetElementById("setProfileProps").style.visibility = "visible";
34![]() GetElementById("logoutId").style.visibility = "visible";
        GetElementById("logoutId").style.visibility = "visible";
35![]() }
    }
36![]() else
    else
37![]() {
    {
38![]() DisplayInformation("没有登录");
        DisplayInformation("没有登录");
39![]() }
    }
40![]() }
}
41![]()
42![]() //验证失败后调用的方法
//验证失败后调用的方法
43![]() function OnAuthenticationFailed(error_object,
function OnAuthenticationFailed(error_object, 
44![]() userContext, methodName)
    userContext, methodName)
45![]() {
{    
46![]() DisplayInformation("验证过程中发生如下错误: " +
    DisplayInformation("验证过程中发生如下错误: " +
47![]() error_object.get_message());
        error_object.get_message());
48![]() }
}
49![]() //加载个性化配置的方法-调用个性化服务的方法
//加载个性化配置的方法-调用个性化服务的方法
50![]() function LoadProfile()
function LoadProfile()
51![]() {
{
52![]() Sys.Services.ProfileService.load(null,
    Sys.Services.ProfileService.load(null, 
53![]() OnLoadCompleted, OnProfileFailed, null);
        OnLoadCompleted, OnProfileFailed, null);
54![]() }
}
55![]()
56![]() //保存个性化配置-调用个性化服务的方法
//保存个性化配置-调用个性化服务的方法
57![]() function SaveProfile()
function SaveProfile()
58![]() {
{
59![]() Sys.Services.ProfileService.properties.Backgroundcolor =
    Sys.Services.ProfileService.properties.Backgroundcolor = 
60![]() GetElementById("bgcolor").value;//背景色
        GetElementById("bgcolor").value;//背景色
61![]() Sys.Services.ProfileService.properties.Foregroundcolor =
    Sys.Services.ProfileService.properties.Foregroundcolor =
62![]() GetElementById("fgcolor").value; //前景色
        GetElementById("fgcolor").value; //前景色
63![]() Sys.Services.ProfileService.save(null,
    Sys.Services.ProfileService.save(null, 
64![]() OnSaveCompleted, OnProfileFailed, null);//保存
        OnSaveCompleted, OnProfileFailed, null);//保存
65![]() }
}
66![]()
67![]() //读取个性配置并应用其内容
//读取个性配置并应用其内容
68![]() function OnLoadCompleted(numProperties, userContext, methodName)
function OnLoadCompleted(numProperties, userContext, methodName)
69![]() {
{
70![]() document.bgColor =
    document.bgColor = 
71![]() Sys.Services.ProfileService.properties.Backgroundcolor;
        Sys.Services.ProfileService.properties.Backgroundcolor;
72![]() document.fgColor =
    document.fgColor =   
73![]() Sys.Services.ProfileService.properties.Foregroundcolor;
        Sys.Services.ProfileService.properties.Foregroundcolor;            
74![]() }
}
75![]() //保存配置成功后调用的方法
//保存配置成功后调用的方法
76![]() function OnSaveCompleted(numProperties, userContext, methodName)
function OnSaveCompleted(numProperties, userContext, methodName)
77![]() {
{
78![]() LoadProfile();//加载配置
    LoadProfile();//加载配置
79![]() //隐藏配置div
    //隐藏配置div
80![]() SetProfileControlsVisibility("hidden");
    SetProfileControlsVisibility("hidden");
81![]() }
}
82![]() //配置加载失败时调用的方法
//配置加载失败时调用的方法
83![]() function OnProfileFailed(error_object, userContext, methodName)
function OnProfileFailed(error_object, userContext, methodName)
84![]() {
{
85![]() alert("配置服务调用失败: " + error_object.get_message());
    alert("配置服务调用失败: " + error_object.get_message());
86![]() }
}
87![]() //设置个性化配置DIV是否显示
//设置个性化配置DIV是否显示
88![]() function SetProfileControlsVisibility(currentVisibility)
function SetProfileControlsVisibility(currentVisibility)
89![]() {
{
90![]() GetElementById("setProfileProps").style.visibility =
    GetElementById("setProfileProps").style.visibility = 
91![]() currentVisibility;
        currentVisibility; 
92![]() }
}
93![]()
94![]() //显示消息的方法
//显示消息的方法
95![]() function DisplayInformation(text)
function DisplayInformation(text)
96![]() {
{
97![]() document.getElementById('placeHolder').innerHTML +=
    document.getElementById('placeHolder').innerHTML += 
98![]() "<br/>"+ text;
    "<br/>"+ text;
99![]() }
}
100![]() //javascript的方法getElementById被封装成C#用法
//javascript的方法getElementById被封装成C#用法  
101![]() function GetElementById(elementId)
function GetElementById(elementId)
102![]() {
{
103![]() var element = document.getElementById(elementId);
    var element = document.getElementById(elementId);
104![]() return element;
    return element;
105![]() }
}
106![]() //判断是否正确加载了ajax类库
//判断是否正确加载了ajax类库
107![]() if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
108![]()
109![]()

2
 //登录按钮事件
//登录按钮事件3
 function OnClickLogin()
function OnClickLogin()4
 {
{5
 Sys.Services.AuthenticationService.login(
    Sys.Services.AuthenticationService.login(6
 document.form1.userId.value,
        document.form1.userId.value,7
 document.form1.userPwd.value,false,null,null,
        document.form1.userPwd.value,false,null,null,8
 OnLoginComplete, OnAuthenticationFailed,
        OnLoginComplete, OnAuthenticationFailed,9
 "User context information.");
        "User context information.");10
 }
}11
 // 注销按钮事件
// 注销按钮事件12
 function OnClickLogout()
function OnClickLogout()13
 {
{14
 Sys.Services.AuthenticationService.logout(
    Sys.Services.AuthenticationService.logout(15
 null, OnLogoutComplete, OnAuthenticationFailed,null);
        null, OnLogoutComplete, OnAuthenticationFailed,null);16
 }
}17
 //注销完成调用的方法
//注销完成调用的方法18
 function OnLogoutComplete(result,
function OnLogoutComplete(result, 19
 userContext, methodName)
    userContext, methodName)20
 {}
{}        21

22
 //登录完成调用的方法
//登录完成调用的方法23
 function OnLoginComplete(validCredentials,
function OnLoginComplete(validCredentials, 24
 userContext, methodName)
    userContext, methodName)25
 {
{26
 //如果验证成功
//如果验证成功27
 if(validCredentials == true)
    if(validCredentials == true)28
 {
    {29
 DisplayInformation("欢迎你: " + document.form1.userId.value);//显示欢迎信息
        DisplayInformation("欢迎你: " + document.form1.userId.value);//显示欢迎信息30
 LoadProfile();//加载个性化配置
        LoadProfile();//加载个性化配置31
 // 隐藏不该显示的选择
        // 隐藏不该显示的选择32
 GetElementById("loginId").style.visibility = "hidden";
        GetElementById("loginId").style.visibility = "hidden";33
 GetElementById("setProfileProps").style.visibility = "visible";
        GetElementById("setProfileProps").style.visibility = "visible";34
 GetElementById("logoutId").style.visibility = "visible";
        GetElementById("logoutId").style.visibility = "visible";35
 }
    }36
 else
    else37
 {
    {38
 DisplayInformation("没有登录");
        DisplayInformation("没有登录");39
 }
    }40
 }
}41

42
 //验证失败后调用的方法
//验证失败后调用的方法43
 function OnAuthenticationFailed(error_object,
function OnAuthenticationFailed(error_object, 44
 userContext, methodName)
    userContext, methodName)45
 {
{    46
 DisplayInformation("验证过程中发生如下错误: " +
    DisplayInformation("验证过程中发生如下错误: " +47
 error_object.get_message());
        error_object.get_message());48
 }
}49
 //加载个性化配置的方法-调用个性化服务的方法
//加载个性化配置的方法-调用个性化服务的方法50
 function LoadProfile()
function LoadProfile()51
 {
{52
 Sys.Services.ProfileService.load(null,
    Sys.Services.ProfileService.load(null, 53
 OnLoadCompleted, OnProfileFailed, null);
        OnLoadCompleted, OnProfileFailed, null);54
 }
}55

56
 //保存个性化配置-调用个性化服务的方法
//保存个性化配置-调用个性化服务的方法57
 function SaveProfile()
function SaveProfile()58
 {
{59
 Sys.Services.ProfileService.properties.Backgroundcolor =
    Sys.Services.ProfileService.properties.Backgroundcolor = 60
 GetElementById("bgcolor").value;//背景色
        GetElementById("bgcolor").value;//背景色61
 Sys.Services.ProfileService.properties.Foregroundcolor =
    Sys.Services.ProfileService.properties.Foregroundcolor =62
 GetElementById("fgcolor").value; //前景色
        GetElementById("fgcolor").value; //前景色63
 Sys.Services.ProfileService.save(null,
    Sys.Services.ProfileService.save(null, 64
 OnSaveCompleted, OnProfileFailed, null);//保存
        OnSaveCompleted, OnProfileFailed, null);//保存65
 }
}66

67
 //读取个性配置并应用其内容
//读取个性配置并应用其内容68
 function OnLoadCompleted(numProperties, userContext, methodName)
function OnLoadCompleted(numProperties, userContext, methodName)69
 {
{70
 document.bgColor =
    document.bgColor = 71
 Sys.Services.ProfileService.properties.Backgroundcolor;
        Sys.Services.ProfileService.properties.Backgroundcolor;72
 document.fgColor =
    document.fgColor =   73
 Sys.Services.ProfileService.properties.Foregroundcolor;
        Sys.Services.ProfileService.properties.Foregroundcolor;            74
 }
}75
 //保存配置成功后调用的方法
//保存配置成功后调用的方法76
 function OnSaveCompleted(numProperties, userContext, methodName)
function OnSaveCompleted(numProperties, userContext, methodName)77
 {
{78
 LoadProfile();//加载配置
    LoadProfile();//加载配置79
 //隐藏配置div
    //隐藏配置div80
 SetProfileControlsVisibility("hidden");
    SetProfileControlsVisibility("hidden");81
 }
}82
 //配置加载失败时调用的方法
//配置加载失败时调用的方法83
 function OnProfileFailed(error_object, userContext, methodName)
function OnProfileFailed(error_object, userContext, methodName)84
 {
{85
 alert("配置服务调用失败: " + error_object.get_message());
    alert("配置服务调用失败: " + error_object.get_message());86
 }
}87
 //设置个性化配置DIV是否显示
//设置个性化配置DIV是否显示88
 function SetProfileControlsVisibility(currentVisibility)
function SetProfileControlsVisibility(currentVisibility)89
 {
{90
 GetElementById("setProfileProps").style.visibility =
    GetElementById("setProfileProps").style.visibility = 91
 currentVisibility;
        currentVisibility; 92
 }
}93

94
 //显示消息的方法
//显示消息的方法95
 function DisplayInformation(text)
function DisplayInformation(text)96
 {
{97
 document.getElementById('placeHolder').innerHTML +=
    document.getElementById('placeHolder').innerHTML += 98
 "<br/>"+ text;
    "<br/>"+ text;99
 }
}100
 //javascript的方法getElementById被封装成C#用法
//javascript的方法getElementById被封装成C#用法  101
 function GetElementById(elementId)
function GetElementById(elementId)102
 {
{103
 var element = document.getElementById(elementId);
    var element = document.getElementById(elementId);104
 return element;
    return element;105
 }
}106
 //判断是否正确加载了ajax类库
//判断是否正确加载了ajax类库107
 if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();108

109

 
                    
                

 
     
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号