I usually echo at the end of the script instead of in the loop and also send 200 http response.
$result = $page->read($_GET['pageid']);
//check for data
if ($result) {
//page array
$page_arr['pages'] = array();
while ($row =$result->fetch(PDO::FETCH_ASSOC)) {
extract($row);
$page_item = array(
'id'=> $id,
'title' => $title,
'pageid' => $pageid,
'pagecontent' =>html_entity_decode($pagecontent),
'mdkeywords' => $mdkeywords,
'description' =>$description,
'date_added' =>$date_added,
'hasAudio' => $hasAudio,
'excludeSearch' =>$excludeSearch
);
//push to data
array_push($page_arr['pages'], $page_item);
}
http_response_code(200);
} else {
$page_arr['message']="Nothing Here!!!";
}
echo json_encode($page_arr);