當我使用向IE發送數據給控制器的AJAX請求時,它發送空數據。當我使用Chrome或Firefox時,來自鍵/值對的數據存在於控制器的參數變量中。AJAX使用IE發送空數據時
這裏是我的javascript函數:
$(".input-group.date").datepicker({
autoclose: true
}).on('changeDate', function (ev) {
var schoolId = $(this).attr('data-schoolId');
var date = new Date(ev.date).toUTCString();
var schoolName = $(this).attr('data-schoolName');
$.ajax({
url: "@Url.Action("ChangeFulfillmentDate", "Admin")",
type: "POST",
data: {
'newDate': date,
'schoolId': schoolId
},
success: function (data) {
if (!data.success) {
var n = noty({
text: 'Hold up! Something went wrong...<br />' + data.message,
layout: 'top',
type: 'error',
killer: true,
closeWith: ['button']
});
}
else {
var n = noty({
text: 'Fulfillment date for ' + schoolName + ' updated successfully',
layout: 'bottomRight',
type: 'success',
timeout: 3000,
killer: true,
closeWith: ['hover']
});
}
},
error: function (xhr, status, error) {
var n = noty({
text: 'Hold up! Something went wrong...<br />' + xhr.responseText,
layout: 'top',
type: 'error',
killer: true,
closeWith: ['button']
});
}
});
});
Ajax響應的錯誤,我得到的是:
The parameters dictionary contains a null entry for parameter 'newDate' of non-nullable type 'System.DateTime' for method 'System.Web.Mvc.JsonResult ChangeFulfillmentDate(System.DateTime, Int32)' in 'CurrReplenishment.Controllers.AdminController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
參數名:參數
爲什麼我的AJAX調用不發送正確的價值觀對於鍵/值對?我確信這些javascript變量中有數據,因爲它可以在Chrome和Firefox中使用。
調試這條線在IE中。 'var date = new Date(ev.date).toUTCString();'你的問題可能與ajax無關。很可能IE不會將'ev.date'識別爲日期字符串。 –
我不這麼認爲。 'date'變量填充了類似於「Tue,2014年6月17日00:00:00 UTC」的數據。 –