客户端.html
我如何在客户端编写这个 json 数据检索,以便循环出每个框和其中的样式。
像这样的东西是行不通的......
success: function(output) {
var records = output.data;
var str = "";
if (records) {
alert(records.length);
for (var i = 0; i < records.length; i++) {
for (var j in records[i]) {
str += j + " --> " + records[i][j] + "\n";
}
}
}
}
测试.php
$sql= "select id, style from table";
$result = mysql_query ($sql);
while($r = mysql_fetch_assoc($result)) {
$id = $r['id'];
$rows[$id] = $r;
}
$data = array(
'data' => $rows,
'debug' => $msg,
'status' => 1
);
借助构建功能中的 php 转换为 json 后的数据。(我想要的格式)
{
"data": {
"box1": { "style":"position: absolute;", "id":"box1" },
"box2": { "style":"position: relative;", "id":"box2" },
"box88": { "style":"position: relative;", "id":"box3" }
},
"debug":"feedback to client end",
"status":1
}