header('Content-Type: application/json');
$json = array('status' => false);
$bd = new MySQLi('host', 'user', 'password', 'bd');
$query = $bd->query('SELECT * FROM `songs` ORDER BY `id` DESC');
$len = $query->num_rows;
if($len) {
$json['status'] = true;
$json['data'] = array();
for($i=0; $i<$len; $i++) $json['data'][$i] = $query->fetch_assoc();
}
$bd->close();
echo json_encode($json);
$.post('/ajax.php', {}, function(json) {
json = JSON.parse(json);
if(json.status) {
//code
// for(var i=0; i<json.data.length; i++) alert(json.data[i].title);
}
else alert('Error!');
});