I want to count the items of an array returned by json. When I use response.length
, it counts all the characters in the array(I guess so) while what I want it to do is to count how many items are there in the array. Same method works in another pages, just not with this one.
This is the php code:
...$response[] = array("id" => $row['appid'],
"hour" => $row['hour'],
"tname" => $tname,
"tsurname" => $tsurname,
"cname" => $cname,
"csurname" => $csurname,
"cgsm" => $cgsm,
"cemail" => $cemail,
"cdept" => $cdept,
"cdeg" => $cdeg,
"purpose" => $purpose,
"clientnotshown" => $row['clientnotshown']);
};
if(isset($response)){
echo json_encode($response);
} else {
$response = array("val" => 0);
echo json_encode($response);
};
Javascript code:
function updateTable() {
var getData = {
date: $("#displaydate").val(),
operation:"getData"
}
$.post( "printoperations.php", getData).done(function( response ) {
if (response.val != 0){
alert("so far so good")
var arrayLength = response.length
alert(response)
alert(arrayLength)}
};
Here is a picture of what I get. I want to get the count of items, which in this case is 2.