Copy codeThe Code is as follows: <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
<Script src = "js/Jquery1.7.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ('# Button1'). click (function (){
Var username = $ ('# txtUserName'). val ();
Var pwd = $ ('# txtPwd'). val ();
$. Ajax ({
Type: "post ",
ContentType: "application/json ",
Url: "WebService1.asmx/Login ",
Data: "{username: '" + username + "', pwd: '" + pwd + "'}",
Success: function (bukeyi ){
If (bukeyi. d = 'true '){
Window. location = 'htmlpage1.htm ';
}
Else {
$ ('# Divinfo'). text ("incorrect user name or password ");
}
}
})
})
})
</Script>
</Head>
<Body>
Username <input id = "txtUserName" type = "text"/> <br/>
Password <input id = "txtPwd" type = "text"/> <br/>
<Input id = "Button1" type = "button" value = "Logon"/> <br/>
<Div id = "divinfo"> </div>
</Body>
</Html>
------ WebService1.asmx ----Copy codeThe Code is as follows: using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. Services;
Namespace ajax11
{
/// <Summary>
/// Summary of WebService1
/// </Summary>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
[System. ComponentModel. ToolboxItem (false)]
// To allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.
[System. Web. Script. Services. ScriptService]
Public class WebService1: System. Web. Services. WebService
{
[WebMethod]
Public string HelloWorld ()
{
Return "Hello World ";
}
[WebMethod]
Public string ValidateUser (string username)
{
If (username = "onlifes ")
{
Return "the user name is in use. Please select another ";
}
Else
{
Return "available, please continue ";
}
}
[WebMethod]
Public string GetDate ()
{
Return DateTime. Now. ToString ("yyyy-MM-dd hh: mm: ss ");
}
[WebMethod]
Public string Login (string username, string pwd)
{
If (username = "admin" & pwd = "888888 ")
{
Return "true ";
}
Else
{Return "false ";}
}
}
}