I am sending a JSON object to a PHP file, The PHP does some manipulation and returns a JSON string:
$('button#indexOpener').on('click', function() {
var aUsername = $('input#edUsername').val();
var aPassword = $('input#edPassword').val();
if (($.trim(aUsername) != '') && ($.trim(aPassword) != '')) {
var str = $("#form_login :input").serializeArray();
$.post("<?php echo URL; ?>ajax/checklogin", str, function(data) {
alert(data.edUsername);
});
}
else {
alert('Please insert a valid username and password');
alert("<?php echo URL; ?>/ajax");
}
});
the PHP echoes a JSON object:
echo json_encode($_POST);
but when I try to alert the data with jQuery:
function(data) {
alert(data.edUsername);
}
is displaying the message undefined. I am sure it is something stupid but I cannot see what I am doing wrong, can you help?
$("#form_login :input").serializeArray();Doesn't it should be like this:$("#form_login").serializeArray();