Talking about JSON

Source: Internet
Author: User

1. Data that is queried from the database and 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. Turn the data into JSON

The code is as follows:
$data _arr=array ($xdata, $ydata)
Json_encode ($data _arr);

Ajax call data in 3.HTML pages

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!");
var jsondata = eval ("+ Strreult +"));
var xData = jsondata[0];
var ydata = jsondata[1];
var namestr = jsondata[2];
},
Error:function () {
Alert ("fail!");
}
});

The above mentioned is about the Json_encode use of the entire content of the method, I hope to help you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.