Я использую следующий код:
$(document).ready(function() {
$.ajax({
url: "tiles/chartValue.php",
datatype: 'json',
type: 'POST',
success: function(data){
$.each(data, function(key, value) {
alert(key + ': ' + value);
});
});
});
Вот здесь chartValue.php
<?php
include("../functions.php");
$DAO=new DBUtil();
$DAO->initDB("../db/connection.properties");
$k=$DAO->getChart();
echo json_encode($k);
?>
Вот функция getChart для functions.php
public function getChart()
{
$sql = "SELECT a.total, round( (b.active *100) / total ) active_user, round( (c.inactive *100) / total ) inactive_user
FROM
(
SELECT IFNULL( count( * ) , 0 ) total FROM ashekan_info
)a,
(
SELECT IFNULL( count( * ) , 0 ) active FROM ashekan_info WHERE is_active =1
)b,
(
SELECT IFNULL( count( * ) , 0 ) inactive FROM ashekan_info WHERE is_active =0
)c";
$result=mysql_query($sql,$this->connect()) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$json = array('total' =>$row['total'],
'active_user' =>$row['active_user'],
'inactive_user' =>$row['inactive_user']
);
return $json;
}
Я получаю результат в firebug: {"total": "1", "active_user": "0", "inactive_user": "100"}
проблема в том, что он показывает каждый символ в окне предупреждения.т.е.: {, ", t и т. д.
как я могу получить 1, 0, 100? заранее спасибо.