Brief discussion on Json_encode usage and Json_encode
1. Data that is queried from the database and placed in the array
Copy the Code code as follows:
$query =mysql_query ($SQL);
while ($row = Mysql_fetch_array ($query)) {
$xdata []= $row [' eventdate '];
$ydata []=intval ($row [' data ']);
}
2. Turning data into JSON
Copy the Code code as follows:
$data _arr=array ($xdata, $ydata)
Json_encode ($data _arr);
Ajax call data in 3.HTML pages
Copy the Code code 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 about the json_encode use of the whole content of the method, I hope to be helpful to everyone.
http://www.bkjia.com/PHPjc/963851.html www.bkjia.com true http://www.bkjia.com/PHPjc/963851.html techarticle Talking about the usage of Json_encode, Json_encode 1. The data that is queried from the database is copied into the array in the following code: $query =mysql_query ($SQL); while ($row = Mysql_fetch_ A ... ..