I'm using dataTable and I'm having the Json parse error. Here is my code:
jQuery(function($){
$('#allusers').dataTable({
"sAjaxSource": document.URL+"/allusers.php"
});
$.ajax({
url: document.URL+"/allusers.php",
success: function(data){
alert (data);
}
});
});
So inserted the $.ajax
part so that I could see the data being returned. (Well I could also see it using firebug, just wanna make sure) and the response that I am getting is the HTML code instead of the JSON object.
here is the snippet of allusers.php:
$dataArr['aaData'] = Array();
$res = $mysqli->query($query);
$numrows = $res->num_rows;
$output = array('iTotalRecords' => $numrows, "iTotalDisplayRecords" => 10, "aaData" => array() );
if ($res = $mysqli->query($query)){
while($row = $res->fetch_array(MYSQLI_ASSOC)){
$r = Array();
foreach($row as $key=>$value){
$r[] = $value;
}
$output['aaData'][] = $r;
}
} else
die(mysql_errno());
$output['err'] = 'hello';
header('Content-Type: application/json');
echo json_encode($output);
exit();
I already tried var_dump($r)
to check the contents of $output and I don't see a problem with it.
So the result that I'm getting is:
<!DOCTYPE html>
<html class="home">
<head>
<title>User List</title>
...
it basically returns the html content of the whole page. Is the problem within the javascript or php? Thanks in advance for the help!