컨트롤러 메서드에 AJAX 호출을 수행하는 JavaScript 메서드가 있습니다. 이 컨트롤러 메서드는 JsonResult 메서드로, 사전 객체를 다시 JavaScript로 반환합니다. 하지만이 객체 (예 : dictionaryObject.count, dictionaryObejct [i] .value 등)에 대한 모든 작업을 수행하면 "정의되지 않음"이 표시됩니다. 내가 어떻게이 객체를 사용해야하는지에 대한 어떤 생각?JsonResult 메서드에서 반환되는 사전을 트래버스하는 방법은 무엇입니까?
function MakeControllerMethodCallFunction(stringParam1, stringParam2) {
// Remove all rows from table so that table can have latest data
$('#TableModal tr').each(function (i, row) {
var $row = $(row);
$row.remove();
});
$("#TableModal thead").append("<tr><th>" + stringParam1+ " Details " + "</th></tr>");
//Resolving the server side method URL
var websitePath = GetRootWebSitePath();
var getUrl = websitePath + "/Home/GetDetails";
//Creating parameters for Ajax call
var params = "{\"ParamOne\" : \"" + stringParam1+ "\" , \"ParamTwo\" : \"" + stringParam2+ "\" }";
//AJAX Call
$.ajax({
url: getUrl,
type: 'POST',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: params,
success: MakeControllerMethodCallFunction_Success,
error: function (xhr, status, thrownError) {
alert("Get Details error");
}
});
}
//On Success of MakeControllerMethodCallFunction() this will be hit and values will be bind to the table
function MakeControllerMethodCallFunction_Success(dictionaryObject) {
var Size = 0;
if (dictionaryObject!= null) {
Size = (dictionaryObject!= null) ? dictionaryObject.count : 0;
}
if (Size != null) {
for (var i = 0; i < Size; i++) {
var newRow = "<tr>";
if (dictionaryObject!= null && dictionaryObject.count> 0 && dictionaryObject[i] != null) {
newRow += "<td>" + dictionaryObject[i].name + "</td>" + "<td>" + dictionaryObject[i].value + "</td>";
}
else {
newRow += "<td></td>";
}
newRow += "</tr>";
$("#TableModal tbody").append(newRow);
}
}
}
Chrome에서 F12를 누르십시오. (모두 Chrome을 사용하고 있습니까?) JS 개발에 도움이되는 다양한 도구가 제공됩니다. 브레이크 포인트를 치고 데이터의 모양을 검사하고 콘솔 평가판 및 오류 스타일의 표현식을 평가하십시오. –
VS의 QuickWatch 창을 사용하고있었습니다. 어쨌든, 이제 끝났어. TY. :) – Abhid