这是我的ajax调用:
var totalCost = 0;
function GetTotalCost(start, end, rID)
{
$.ajax({
url: '@Url.Action("CalculateTotalcost")',
type: 'POST',
data: JSON.stringify({ start:start, end:end, rID:rID}),
dataType: 'json',
processdata: false,
contentType: 'application/json; charset=utf-8',
success: function (data) { totalCost = data; }
// error: function (xhr, ajaxOptions, thrownError) { $('.datepicker1').datepicker("hide"); },
// complete: function (x, y) { $('.datepicker1').datepicker("refresh"); }
});
}
这是我调用ajax的函数:
$('.datepicker2').datepicker({
dateFormat: 'dd/mm/yy',
firstDay: 1,
yearRange: '2012:2100',
beforeShowDay: function (date) {
var day = date.getDate();
if (day in alreadyTakenDays) {
return [false, '', alreadyTakenDays[day]];
}
else return [true, 'IsActive'];
},
onChangeMonthYear: function (year, month, inst) {
alreadyTakenDays = {};
getEvents(month, year);
},
onSelect: function (dateText, inst) {
var end = dateText.substring(0, 2);
console.log(end);
var rID = $('#RoomID').val();
console.log(rID);
var startingHole = $('#DateOne').val();
var start = startingHole.substring(0, 2);
console.log(start);
GetTotalCost(start, end, rID);
document.getElementById('TotalCost').value = totalCost.toFixed(2);
}
});
执行 jQuery 脚本后,totalCount总是得到0? 为什么会这样?我该怎么办?我想在 ASP.NET MVC 3 中将 totalCount 指定给 Html.TextBoxFor,这就是我需要 totalCount 的原因。请帮忙。