I’m having difficulty sending a variable together with an ajax request. Here is my html/js code:
<input id="login-username" class="input" type="text" placeholder="Username"/>
<input id="login-password" class="input" type="password" placeholder="Password"/>
<a href="javascript:void(0);" id="submit-login" class="btn btn-small btn-info"><strong>sign in</strong></a>
$("#submit-login").click(function(e){
e.preventDefault();
var usernameReg = /^[a-zA-Z0-9]+$/;
var username = $("#login-username").val();
var password = $("#login-password").val();
alert(username);
alert(password);
if(!usernameReg.test(username)){
$("#input-login-username").html("some html");
return false;
} else if(!usernameReg.test(password)){
$("#input-login-password").html("some html");
return false;
} else if((username == "") || (password = "")){
$("#input-login-username").html("<strong><small>Empty field(s)</small></strong>");
return false;
} else {
$.ajax({
type: 'POST',
url: '?a=validate',
data: {
"password" : password,
"username" : username
},
success: function(data){
some statements
}
});
}
});


The value of the password element is received as displayed in the first image. And there are no misspellings in the object literal that is send with the ajax. What am i doing wrong?
=≠==: