【发布时间】:2009-01-17 12:06:07
【问题描述】:
我找不到任何关于使用 jQuery 获取 JSON 总记录数的信息。
这是返回的 JSON:
{"Email":"Please enter your Email.","Password":"Please enter a password."}
这是我的代码:
$(function() {
$("#btnSubmit").click(function() {
$.ajax({
url: "/account/signup",
type: "POST",
dataType: "json",
data: {
Email: $("#strEmail").val(),
Password: $("#strPassword").val()
},
success: function(j) {
$(".errMsg").hide();
alert(j.length); // I couldn't get the total count
$.each(j, function(n) {
$("#err" + n).html(j[n]);
$("#err" + n).show();
})
},
error: function(req, status, error) {
alert(req);
}
});
});
});
【问题讨论】:
-
但是成功处理程序中的 $.each 显示了正确的记录?
-
是的,除了总记录数之外,一切正常。
-
为什么需要记录数? $.each 按预期工作,对吗?