Jquery Ajax calls WebService

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.