JQuery AJAX invoke WebService implementation code _jquery

Source: Internet
Author: User
Tags eval
Use jquery to invoke webservice of other projects
Implementing logon Verification Features
HTML Enter user name password:
Code
Copy Code code as follows:

<table style= "width:400px" >
<tr>
<td style= "width: 200px "class=" >
Login ID:
</td>
<td style= "width:200px" class= "left" >
<in Put id= "Txtloginid" type= "text" style= width:190px; "value=" "/>
</td>
</tr>
<tr>
<td style= "width:200px" class= "left" >
Login Password:
</td>
<td style= "width:200p X "class=" left >
<input id= "TXTLOGINPW type=" password "style=" width:190px; "value=" "/>
</td>
</tr>
<tr>
<td style= "width:200px" class= "center" >
<input id= "Btnsignin" va Lue= "Sign in" class= "button" readonly/>
</td>
<td style= "width:200px" class= "center" >
& Lt;input id= "Btnsignup" value= "Sign Up" class= "button" readonly/>
</td>
</tr>
</table >

jquery References and logon events
Code
Copy Code code as follows:

<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 similar: var serviceurl = "Http://localhost:1742/SoldierServices.asmx";
WebService Code:
Code
Copy Code code as follows:

<summary>
Summary description for Soldierservices
</summary>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
[ToolboxItem (False)]
To allow this Web Service to is 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]
Public User GetUserInfo (string UserID)
{
loginbusiness lb = new loginbusiness ();
return lb. GetUserInfo (UserID);
}
}

Note: [System.Web.Script.Services.ScriptService] is annotated by default, 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.