由于某些原因,我的JSON结果未定义。这是我的JS代码:
$(document).ready(function () {
$('#submit').click(function (e) {
e.preventDefault();
$.getJSON("/BMICalculations/GetJSONData", function (data) {
var div = $('#ajaxDiv');
div.html("<br/> " + "Persons received from server: " + "<br/>");
$.each(data, function (i, item) {
printBMI(div, item);
});
});
});
});
function printBMI(div, item) {
div.append("<br/>" + "BMI: " + item.BMIInfo);
}
这是我的控制器代码:
public JsonResult GetJSONData()
{
var x = db.BMICalculations.ToList();
var last = x.Last();
var data = new
{
BMICalculation = last.BMICalc,
BMIInfo = last.BMIMeaning
};
return Json(data, JsonRequestBehavior.AllowGet);
}
该网页显示“未定义的”字样
这是一张照片: