Background code:
[WebMethod]
public static string Logintest (string usercode, string password)
{
Usermanagecenterservice service = new Usermanagecenterservice ();
String msg = string. Empty;
Service. Authenticateuser (usercode, password, 10000, out msg);
if (msg = = "Verify Success")
{
String callbackurl = system.configuration.configurationmanager.appsettings["Callbackurl"]. ToString ();
msg = "{\" sign\ ": \" authenticated\ ", \" url\ ":" + ' \ "' + Callbackurl + ' \" ' + "}";
return msg;
}
return msg;
}
Front Code:
$ (document). Ready (function () {
$ ("#btnlogin"). Click (function () {
if (Customlogin () = False) {
$.ajax (
{
Type: "POST",
ContentType: "Application/json",
URL: "Login.aspx/logintest",
Data: "{' Usercode ': '" + $ ("#txtUserName"). Val () + "', ' Password ': '" + $ ("#txtPassword"). Val () + "'}",
DataType: "JSON",
Success:function (msg) {
Ajaxobj = eval ("(" + MSG.D + ")");
if (ajaxobj.sign = = "Authenticated") {
Window.location.href = Ajaxobj.url;
}
else {
alert (MSG.D);
}
}
});
}
});
});
Ajax invoke background WebService return JSON characters