Home > php教程 > php手册 > 浅谈json_encode用法,浅谈json_encode

浅谈json_encode用法,浅谈json_encode

WBOY
Release: 2016-06-13 09:13:30
Original
890 people have browsed it

浅谈json_encode用法,浅谈json_encode

1.从数据库中查询出来的数据,放在数组中

复制代码 代码如下:
$query=mysql_query($SQL);
 while($row = mysql_fetch_array($query)){
        $xdata[]=$row['EventDate'];
         $ydata[]=intval($row['data']);
    }

2.将数据转成json

复制代码 代码如下:
  $data_arr=array($xdata,$ydata)
  json_encode($data_arr);

3.HTML 页面中  AJAX调用数据

复制代码 代码如下:
$.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!");
   }
  });

以上所述就是关于json_encode使用方法的全部内容了,希望对大家能有所帮助。

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template