我有一个返回 json 对象的控制器,我检查了控制器,它运行良好。
这是我的控制器的示例结果
{"CompliantCount":0,"NonCompliantCount":0,"StatusOfRiskItems":[{"Id":4,"Status":"Closed","Count":0},{"Id":1,"Status":"Open","Count":0},{"Id":2,"Status":"Mitigating Control Implemented","Count":0},{"Id":3,"Status":"Risk Accepted","Count":0}],"RiskLevelBreakdownOfOpenItems":[{"Id":0,"RiskLevel":"N/A","Count":0},{"Id":1,"RiskLevel":"Low","Count":0},{"Id":2,"RiskLevel":"Medium","Count":0},{"Id":3,"RiskLevel":"High","Count":0},{"Id":4,"RiskLevel":"Very High","Count":0}],"RiskLevelStatusPerDepartment":[],"CompliancePerDepartment":[],"CurrentRiskLevel":"N/A","ComplianceRating":NaN}
但是当我在 ajax 中使用 json 时,它返回 null
function RiskRegisterReport(siteId, programId, departmentId, status, auditType, auditor, auditDate) {
var _data;
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8;",
url: hostpath + "/RiskRegister/RiskRegisterReport/",
dataType: "json",
async: false,
data: {
siteId: siteId,
programId: programId,
departmentId: departmentId,
statusId: status,
auditType: auditType,
auditor: auditor,
auditDate: auditDate
},
success: function (data) {
/// after getting the data
/// push the data.Compliant and data.NonCompiant to the array
_data = data;
}
});
return _data;
}