对于这段简单的代码,我需要一双新的眼睛,谢谢。
var totalMessageCount = 0;
$.get("/Messages/GetVendorMessageCount/", { vendorId: "@ViewBag.VendorId" })
.done(function (data) {
totalMessageCount = totalMessageCount + Number(data);
$(".MessageCount").html(data);
});
$.get("/Messages/GetVendorNotifyCount/", { vendorId: "@ViewBag.VendorId" })
.done(function (data) {
totalMessageCount = totalMessageCount + Number(data);
$(".NotifyCount").html(data);
});
$.get("/Messages/GetVendorTaskCount/", { vendorId: "@ViewBag.VendorId" })
.done(function (data) {
totalMessageCount = totalMessageCount + Number(data);
$(".TaskCount").html(data);
});
console.log("-" + totalMessageCount);
$(".TotalMessageCount").html(totalMessageCount);
我的控制器为每个.get返回正确的int值,它们正确显示。问题是totalMessageCount
最后为零。所以出于某种原因,totalMessageCount = totalMessageCount + Number(data)
行似乎不起作用。这一定是我做的蠢事,过了漫长的一天......谢谢