【发布时间】:2020-03-09 07:21:38
【问题描述】:
我的控制是,
<input type="date" id="DecDate" name="birthday">
我保存在db中,可以用这种形式查看,
3/10/2020 12:00:00 AM
当我尝试更新相同的记录时,我会根据来自 Ajax 的 json 格式的响应将其填充到“DecDate”中。
我试过了,
$('#DecDate').val(response.DecisionDate);
它没有显示任何日期。
我的警报响应显示我上面的日期与“/Date(1583787600000)/”相同
我不知道为什么它在警报时显示不同以及我应该如何控制它。
编辑:
$.ajax({
type: "GET",
url: "@Url.Action("JqueryFillControl")",
contentType: "application/json; charset=utf-8",
data: { id: Id },
dataType: "json",
success: function (response) {
if (response != null) {
const d = new Date(response.DecisionDate);
const formattedDate = d.getFullYear() + '-' + ("0" + (d.getMonth() + 1)).slice(-2) + '-' + ("0" + d.getDate()).slice(-2)
$('#DecDate').val(formattedDate);
} else {
alert("Something went wrong");
}
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
【问题讨论】:
标签: jquery ajax date datetime model-view-controller