当我使用向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”的数据。 –