Reputation: 292
$('#loginbtn').click(function() {
var userName = document.getElementById('uid').value;
var password = document.getElementById('pwd').value;
$.ajax({
type: "POST",
url: "/LoginNew.aspx/Authenticate",
data: "{ 'userName': '" + userName + "' ,'password': '" + password + "' }",
async: false;
contentType: "application/json; charset=utf-8",
dataType: "json",
success: a(),
error: function(e) {
alert(e.valueOf());
}
});
alert("test");
function a() {
window.location.href = "Login.aspx";
}
});
As I have accepted the answer its goes to the server side code authenticates user and control passes to "a" function but it does not display login.aspx page...Any clues?
Upvotes: 0
Views: 90
Reputation: 943556
The JSON you are generating is invalid. Don't try generating JSON by hand, use an JSON library.
JSON.stringify({ userName: userName, password: password })
You are calling a()
instead of assigning a
as the success handler. Remove the ()
if you want to assign the function instead of its return value.
Upvotes: 2
Reputation: 388316
it should be
$('#loginbtn').click(function() {
var userName = document.getElementById('uid').value;
var password = document.getElementById('pwd').value;
$.ajax({
type : "POST",
url : "/LoginNew.aspx/Authenticate",
data : {
userName: userName ,
password: password
},
async : false, // not ; need to use ,
contentType : "application/json; charset=utf-8",
dataType : "json",
success : a, // pass the callback reference, don't invoke it
error : function(e) {
alert(e.valueOf());
}
});
alert("test");
function a() {
window.location.href = "Login.aspx";
}
});
Upvotes: 3