Use jquery to call WebService of other projects
Implement login verification
Enter the username and password in HTML:
Code
< Table Style = "Width: 400px" >
< Tr >
< TD Style = "Width: 200px" Class = "Left" >
Login ID:
</ TD >
< TD Style = "Width: 200px" Class = "Left" >
< Input ID = "Txtloginid" Type = "Text" Style = "Width: pixel PX ;" Value = "" />
</ TD >
</ Tr >
< Tr >
< TD Style = "Width: 200px" Class = "Left" >
Login Password:
</ TD >
< TD Style = "Width: 200px" Class = "Left" >
< Input ID = "Txtloginpw" Type = "Password" Style = "Width: pixel PX ;" Value = "" />
</ TD >
</ Tr >
< Tr >
< TD Style = "Width: 200px" Class = "Center" >
< Input ID = "Btnsignin" Value = "Sign in" Class = "Button" Readonly />
</ TD >
< TD Style = "Width: 200px" Class = "Center" >
< Input ID = "Btnsignup" Value = "Sign Up" Class = "Button" Readonly />
</ TD >
</ Tr >
</ Table >
Jquery reference and logon events
Code
< Script SRC = "JS/jquery-1.4.2.min.js" Type = "Text/JavaScript" > </ Script >
< Script Type = "Text/JavaScript" Language = "JavaScript" >
$ (Document). Ready ( Function ()
{
$ ( ' # Btnsignin ' ). Click
( Function ()
{
$. Ajax
(
{
Type: " Post " ,
Contenttype: " Application/JSON " ,
URL: serviceurl + " /Userlogin " ,
Data: " {Userloginid :' " + $ ( ' # Txtloginid ' ). Val () + " ', Userloginpw :' " + $ ( ' # Txtloginpw ' ). Val () + " '} " ,
Datatype: ' JSON ' ,
Success: Function (Result)
{
VaR User = Eval (result. D );
Location. href = " Welcome. aspx? Userid = " + User. userid
},
Error: Function (Result, status)
{
If (Status = ' Timeout ' )
{
Alert ( " The request timed out, Please resubmit " );
}
Else
{
If (Result. responsetext ! = "" )
{
Eval ( " Exception = " + Result. responsetext );
Alert (exception. Message );
}
}
}
}
);
}
);
});
$ (Document). Ready ( Function ()
{
$ ( ' # Btnsignup ' ). Click
( Function ()
{
Location. href = " Signup/signup. aspx " ;
})
});
</ Script >
Serviceurl is similar to: var serviceurl = "http: // localhost: 1742/soldierservices. asmx ";
WebServiceCode:
Code
/// <Summary>
/// Summary Description for soldierservices
/// </Summary>
[WebService (namespace = " Http://tempuri.org/ " )]
[Webservicebinding (conformsto = Wsiprofiles. basicprofile1_1)]
[Toolboxitem ( False )]
// To allow this web service to be called from script, using ASP. NET Ajax, uncomment the following line.
[System. Web. Script. Services. scriptservice]
Public Class Soldierservices: system. Web. Services. WebService
{
[Webmethod]
Public User userlogin ( String Userloginid, String Userloginpw)
{
Loginbusiness lb = New Loginbusiness ();
Return lb. userlogin (userloginid, userloginpw);
}
[Webmethod]
PublicUser getuserinfo (StringUserid)
{
Loginbusiness lb= NewLoginbusiness ();
ReturnLB. getuserinfo (userid );
}
}
Note: [system. Web. Script. Services. scriptservice] is annotated by default. You need to remove the annotation.