PHP: lockState.php
require '../dbconn.php';
$query = mysql_query("select id, lockState,name from register_db where Id=1");
$items = array();
while ($row = mysql_fetch_object($query)) {
array_push($items, $row);
}
echo json_encode($items);
Result from query
[{"id":"1","lockState":"No","name":"Local Application"}]
Index.php
$.ajax({
type: "POST",
url: "feed/lockState.php",
data: ({id: 1}),
cache: false,
dataType:"json",
success: function (response) {
alert(JSON.stringify(response)); // [{"id":"1","lockState":"No","name":"Local Application"}]
alert(response.name); //***undefined***
if(response.name=='Local Application'){
callMyFunction(response.name);
}
},
error: function () {
alert("Oops..!! Something wrong!);
}
});
I'm totally lost where I'm doing wrong in using 'Success' response. Even I tried to JSON.parse(response)
and tried to access the key:value, but still same undefined
. Please help.