1. Add the [system. Web. Script. Services. scriptservice] label to the webserver.
Example: Code
[WebService (namespace = "http://abc.org.cn/")]
[Webservicebinding (conformsto = wsiprofiles. basicprofile1_1)]
[System. Web. Script. Services. scriptservice]
Public class user: system. Web. Services. WebService
{
[Webmethod]
Public bool checkpwd (string name, string PWD)
{
Return schoolmis. SYS. User. userfactiory. getuser (). checkpwd (name, PWD );
}
}
2. js $ (
Function ()
{
Function WebService (URL, pars, callback)
{
$. Ajax
({
Async: false,
Data: pars,
URL: URL,
Type: "Post ",
Contenttype: "application/JSON; UTF-8 ",
Datatype: 'json ',
Cache: false,
Success: function (JSON ){
Callback (JSON );
},
Beforesend: function (XML)
{
If (! Pars)
{
XML. setRequestHeader ("Content-Type", "application/JSON; UTF-8 ")
}
},
Error: function (XML, status)
{
If (status = 'error ')
{
Try
{
VaR JSON = eval ('+ XML. responsetext + ')');
Alert ('err: '+ JSON. Message +' \ n' + JSON. stacktrace );
}
Catch (E)
{}
}
Else
{
Alert ('err: '+ status );
}
}
});
}
$ ("# Btnlogin"). Click
(
Function ()
{
VaR N, P, R;
N = $ ("# txtusername"). Val ();
P = $ ("# txtpassword"). Val ();
If (N. Length = 0 | P. Length = 0)
{
Alert ("Please input user name and password .");
$ ("# Txtusername") [0]. Focus ();
If (N. length> 0)
$ ("# Txtpassword") [0]. Focus ();
Return false;
}
WebService (
"User. asmx/login ",
"{Name: '" + N + "', PWD: '" + P + "'}",
Function (Jason)
{
If (! Jason)
{
Alert ("User Name or Password error, Please retry .");
$ ("# Txtpassword") [0]. Focus ();
R = false;
}
Else
{
R = true;
}
}
);
If (r)
Window. Location. href = "/mainform. aspx ";
Return false;
}
)
}
)