I am writing a thing to compare two passwords with each other, if they match the script sends out a response that says it is the same.
I currently have got this code:
$("#repeatPw").keyup(function(){
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data: "'password1'='" + $("#Password").val() + "', 'password2'='" + $("#repeatPw").val() + "'",
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
Now my problem is that i cant get this password1 and password2 in a proper array i can explode in the checkPasswords.php, this posts this:
Array ( ['password1'] => 'fasfasdfasSD2', 'password2'='asdasdasd' )
But this is not a proper array as it only puts password1 in proper array format, how would i go about making password2 in this format too?
Thank you all in advance!
You can do it with a FormData object:
$("#repeatPw").keyup(function(){
var fd = new FormData();
fd.append('password1', $("#Password").val());
fd.append('password2', $("#Password").val());
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data: fd,
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
Or do it the JSON way:
$("#repeatPw").keyup(function(){
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data :{
password1: $("#Password").val(),
password2: $("#repeatPw").val(),
},
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
Create an array and pass it as the ajax post data,
var data=[];
data['password1']= $("#Password").val();
data['password2']= $("#repeatPw").val();
Though you could do this in the client side itself.
if($("#Password").val().trim() == $("#repeatPw").val().trim())
//password Matches
Hopes this help u..
$("#repeatPw").keyup(function(){
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data :{
password1: $("#Password").val(),
password2: $("#repeatPw").val(),
},
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
Try like this
$("#repeatPw").keyup(function(){
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data: {'password1' : $("#Password").val(), 'password2' : $("#repeatPw").val() },
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});