I want to get json result using Jquery. Now I always got 'undefined' result. I can get the json print out using
alert(data);
But always return 'undefined' using
alert(data.first_name);
Jquery client-side code
$.post(
"/modules/services/userlogincheck_new.php",
{
dataType: 'jsonp',
action : "checkpassword",
email : email,
password : password
},
function(data) {
alert(data.first_name);
}
);
PHP server-side
if ($_POST['action'] == "checkpassword") {
$query = "select * from users where email='" . $email . "'";
$result = mysql_query($query, $forumdbcon) or die('Error, insert query failed');
while ($row = mysql_fetch_assoc($result)) {
if (($row['password'] == md5($password))) {
$arr = array("response" => 1, "first_name" => $row['first_name'], "last_name" => $row['last_name'], "address" => $row['address1']);
echo json_encode($arr);
} else {
$arr = array("response" => 2);
echo json_encode($arr);
}
}
}