Wednesday 15 August 2012

Secure Login with Ajax and Jquery

NOTE:-testLogin.php page is where you write login code 
 
function CheckLogin(){
var LoginObj = new Object();
LoginObj.UserName = $("#txtUserName").val();
LoginObj.Password = $("#txtPassword").val();
//Define DTO i.e. Data Transfer Object as follows
var DTO = { 'userLogin': LoginObj };
$.ajax({
type: "POST",
url: "testLogin.php/CheckLogin",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(DTO),
success: function(msg) {
if (msg.d)
$(".alertmsg").html("Valid Login");
else
$(".alertmsg").html("Invalid Login");
},
error: function(xhr, status, error) {
alert("An error has occurred during
processing: " + error);
}
});
}

No comments:

Post a Comment