A brief discussion on the usage of json_encode
1. The data queried from the database is placed in an array
The code is as follows:
$query=mysql_query($SQL);
while($row = mysql_fetch_array($query)){
$xdata[]=$row['EventDate'];
$ydata[]=intval($row['data']);
}
2. Convert data to json
The code is as follows:
$data_arr=array($xdata,$ydata)
json_encode($data_arr);
3. AJAX call data in HTML page
The code is as follows:
$.ajax({
type: "Get",
url: "columndata.php?r=" + Math.floor(Math.random() * 1000 + 1),
data: { 'BeginTime': "" + beginTime + "", "EndTime": "" + endTime + "" , "keyword": "" + keyword + "" },
dataType: "text",
global: false,
async: false,
success: function (strReult) {
if (strReult == "-1") { alert("fail!"); return; }
var jsondata = eval("(" + strReult + ")");
var xData = jsondata[0];
var yData = jsondata[1];
var namestr = jsondata[2];
},
error: function () {
alert("fail!");
}
});
The above is all about the usage of json_encode. I hope it will be helpful to everyone.
http://www.bkjia.com/PHPjc/963983.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963983.htmlTechArticleA brief discussion on the usage of json_encode 1. The data queried from the database is placed in the array with the following code: $query= mysql_query($SQL); while($row = mysql_fetch_array($query)){ $xdata[]=$row['Eve...