Im trying to return a Json array in php to jquery but keep receiving undifined. Im using a jquery Modal to load the login screen the user then logs in and if login is successful i want them redirected if not to display that actions. The code im using is
show: function (dialog) {
$('#loginForm').on('submit', function (e) {
e.preventDefault();
$('input[type=submit]', this).attr('disabled', 'disabled');
var username = $("#username").val();
var password = $("#password").val();
var url = "../_Scripts/login.php";
if (!username) {
$('input[type=submit]', this).removeAttr('disabled');
$("#loginReply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> Please enter your Username.').show().fadeOut(6000);
return false;
} else if (!password) {
$('input[type=submit]', this).removeAttr('disabled');
$("#loginReply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> Please enter your Password.').show().fadeOut(6000);
return false;
} else {
$.post(url, $('#loginForm').serialize(), function (data) {
if (data.status == true) {
// window.location = data.action;
alert(data.status);
} else {
//$("#loginReply").html(data.action).show().fadeOut(10000);
//$("#username").val('');
//$("#password").val('');
//$("#loginProcessGif").hide();
alert(data.status);
}
});
}
});
},
The Login php page looks like so
if($login){
include("mysql-.php");
$password2 = $password;
if($login_query > 0) {
while($row = mysql_fetch_array($sql)){
$idx = $row["id"];
$user = $row["username"];
mysql_query("UPDATE members SET lastlogin=now(), mdhash='$logincode', ip='$ip' WHERE id='$idx'") or die(mysql_error());
}
return json_encode(array('status' => true, 'action' => '../home/'));
}
else {
return json_encode(array('status' => true, 'action' => 'Username/Password incorrect'));
exit();
}
else{
return json_encode(array('status' => true, 'action' => 'Username/Password incorrect'));
exit();
}
Can anyone help to why im getting undefined Vars
Thanks
return
a json encoded array in an if statement and expect it to go anywhere.... is all this code in some function you didn't show? Is there more? – Digital Chris Dec 23 '13 at 19:30