伙计们我在从 ajax 获取数据的 jquery 中遇到一些问题 .. php 文件响应正确并在 jquery 文件警报框中以 json 格式发送数据也确认我从 php 文件中正确获取数据但是当我必须在 html 文件中显示数据时他们没有' t显示..伙计们指导我在脚本中犯了什么错误..
html:
<tr>
<td colspan="6">
<table border="1" width="100%" align="center" class="info">
</table>
</td>
</tr>
jQuery:
$.ajax({
type: "POST",
url: "billingprocess.php",
data: dataString,
success: function (msg) {
alert(msg);
for (var x = 0; x < msg.length; x++) {
var div = $("<tr>").appendTo(".info");
$("<td>").addClass("cols").text(msg[x].B_account).appendTo(div);
$("<td>").addClass("cols").text(msg[x].B_consumer).appendTo(div);
$("<td>").addClass("cols").text(msg[x].month).appendTo(div);
$("<td>").addClass("cols").text(msg[x].net_amount).appendTo(div);
$("<td>").addClass("cols").text(msg[x].due_date).appendTo(div);
$("<td>").addClass("cols").text(msg[x].gross_amount).appendTo(div);
}
}
});
php代码:
if ($rc > 0) {
$i = 0;
while ($i < $rc) {
$r = mysql_fetch_assoc($squery);
$temp[$i] = array("B_account" = > $r['B_account'],
"B_consumer" = > $r['B_consumer'],
"month" = > $r['month']."-".$r['year'],
"net_amount" = > $r['net_amount'],
"due_date" = > $r['due_date']."-".$r['month']."-".$r['year'],
"gross_amount" = > $r['gross_amount']);
$i++;
}
echo json_encode($temp);
}
JSON格式返回数据:
[
{
"B_account": "1014052480080",
"B_consumer": "LA712722",
"month": "Nov-11",
"net_amount": "2107",
"due_date": "30-Nov-11",
"gross_amount": "2282"
},
{
"B_account": "1014052480080",
"B_consumer": "LA712722",
"month": "Dec-11",
"net_amount": "1217",
"due_date": "30-Dec-11",
"gross_amount": "1316"
},
{
"B_account": "1014052480080",
"B_consumer": "LA712722",
"month": "Jan-12",
"net_amount": "737",
"due_date": "31-Jan-12",
"gross_amount": "795"
}
]
这是我认为脚本中的错误的整个代码,但有人解决了这个问题吗?