ajax を使用して、部門名を配列に入力します。$.eachの間、departmentNameには値がありますが、ajaxの終了後、departmentNameをログに記録すると値がありません。
$("#Search").click(function () {
var titleId = $("#title").val();
var departmentGenericId = $("#department").val();
var startDate = $("#startDate").val();
var endDate = $("#endDate").val();
var departmentName = [];
var complianceValue = [];
var nonComplianceValue = [];
var complianceRate = [];
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: '/AcknowledgementAdminLevel/AcknowledgemetnComplianceRate/',
data: {"titleId": titleId,
"departmentGenericId" : departmentGenericId,
"startDate" : startDate,
"endDate" : endDate
},
dataType: "json",
success: function (data) {
$.each(data, function () {
departmentName.push(this.DepartmentName);
complianceValue.push(this.Compliance);
nonComplianceValue.push(this.NonCompliance);
complianceRate.push(this.ComplianceRate);
});
}
});
console.log(departmentName);
});