Brief discussion on Json_encode usage and json_encode_php tutorial

Source: Internet
Author: User

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 ... ..

  • 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.