Home > Backend Development > PHP Tutorial > A brief discussion on json_encode usage, a brief discussion on json_encode_PHP tutorial

A brief discussion on json_encode usage, a brief discussion on json_encode_PHP tutorial

WBOY
Release: 2016-07-13 10:05:14
Original
754 people have browsed it

A brief discussion on the usage of json_encode, a brief discussion on json_encode

1. The data queried from the database is placed in an array

Copy code 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

Copy code The code is as follows:
$data_arr=array($xdata,$ydata)
json_encode($data_arr);

3. AJAX call data in HTML page

Copy code 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 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/963851.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963851.htmlTechArticleA brief discussion on the usage of json_encode, a brief discussion on json_encode 1. The data queried from the database is placed in an array. Copy the code The code is as follows: $query=mysql_query($SQL); while($row = mysql_fetch_a...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template