난 아무것도 찾을 수 없는 couldn& # 39, 궁극적인 목표는 총 JSON 사용하여 기록하십시오 포함한다.
다음은 JSON 반환됨:
,,, ' {" Email" :" 입력하시거나 Email." " Password" :" 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);
}
});
});
});
개체 수를 특성는 JSON 의 OP 움직임을 보이고 있다. 이 일을 할 수 있는 임시 변수를 알고 싶은 것, 그러나 그는 증분됩니다 반복자가 카운트입니다 이터레이션은 전에 시작된다. 필요한 것은 간단한 기능을 제공하는 충족합니다 아래쪽에 있는 [이 페이지] [1].
function countProperties(obj) {
var prop;
var propCount = 0;
for (prop in obj) {
propCount++;
}
return propCount;
}
Json 객체에는 위해 이 일을 잘 한다. 다른 개체의 속성을 파생합니다 그들위에 프로토타입 체인을 추가해야 할 수 있는 것과 해스운프로페티 () 테스트.
[1]: http://www.webdeveloper.com/forum/showthread.php? t = 168120
j.d.length
$.ajax({
type: "POST",
url: "CantTellU.asmx",
data: "{'userID' : " + parseInt($.query.get('ID')) + " }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg, status) {
ApplyTemplate(msg);
alert(msg.d.length);
}
});