function getReportGroups() {
$.ajax({
contentType: "application/json; charset=utf-8",
url: "ReportGroups.ashx",
data: {
'method': 'getReportGroups',
'projectId': '30390'
},
dataType: "json",
success: function (data) {
alert('inside success');
var i = 0;
groupName = [data[i].name];
while (data[i] != null) {
alert([data[i].name]);
alert([data[i].reportGroupId]);
$("#top-node").append("<li item-checked='true' item-expanded='true'><a href=# style=font-weight:bold>" + [data[i].name] + "</a>");
i++;
var id = [data[i].reportGroupId];
getReports(id);
}
},
error: function (result) {
alert("Error- Inside the error loop");
}
});
}
function getReports(id) {
$.ajax({
contentType: "application/json; charset=utf-8",
url: "ReportGroups.ashx",
data: {
'method': 'getReports',
'reportGroupId': id
},
dataType: "json",
success: function (data) {
alert('inside getReports success');
var i = 0;
groupName = [data[i].name];
while (data[i] != null) {
alert([data[i].name]);
i++;
}
},
error: function (result) {
alert("Error- Inside the error loop");
}
});
}
이것은 내 코드입니다. 여기서 getReports (id)를 getReportGroups()에서 매개 변수 id로 호출하면 getReoprts() 함수에서 id가 0으로 전달됩니다. 나는 그 문제가 뭔지 모르겠다. 나는 'id'가 첫 번째 것에 존재 하는지를 확인하기 위해 경고 박스를 사용했다. 나는 getReportsFunction에 유효한 ID를 가지고있다. 하지만 두 번째로 이드를 0으로 만듭니다. 여기서 내가 뭘 잘못하고 있니?jquery 함수를 호출하는 동안 값을 매개 변수로 전달하는 방법
왜 배치되는 변수를 반복? 거기에서 문제를 추적하기 시작할 것입니다 ... – elclanrs
첫 번째 메소드의 성공 호출에서 var id를 선언하고 있습니다. 어쩌면 아약스 호출 외부에서 선언 할 수 있습니다. 따라서 getReportGroups 바로 뒤에있는 아약스 호출 범위 외부에서 호출하십시오. 또한 getReports에있을 때 id가 정확하다는 것을 알리는 곳은 어디입니까? – Nicros
@Nicros : 행 16 –