I want to return JSON from a PHP script.
Do I just echo the result? Do I have to set the Content-Type
header?
If you query a database and need the result set in JSON format it can be done like this:
fetch_array()){
$rows[] = $row;
}
//Return result to jTable
$qryResult = array();
$qryResult['logs'] = $rows;
echo json_encode($qryResult);
mysqli_close($db);
?>
For help in parsing the result using jQuery take a look at this tutorial.