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使用方法的全部内容了,希望对大家能有所帮助。
Statement: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