除了字符串数据类型之外,Html无法正确显示数据 [英] Html failed to display data properly other than string data type
问题描述
我用C#编写的控制器返回了一些值。我调试了代码,返回的所有数据都没问题。但是当我尝试用HTML显示数据时,对于那些不属于String数据类型的数据,数据看起来很奇怪。
例如,如果我的日期时间是2016-09-27那么它会显示为/ Date(123456789)/。
以下是我的javascript格式的脚本:
Hi, I have some values return from my controller written in C#. I have debug the codes and all data returned is ok. But when I try to display the data in HTML, the data appears weird for all those which are not in String data type.
For example, if I have date time which is in 2016-09-27 then it would display as /Date(123456789)/.
Below are my script in javascript format:
PullRecordsForEfficiencyTable: function(firstName, customerId){
firstName = firstName;
customerId = customerId;
$.ajax({
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "POST",
url: "/Customer/LoadRecordsForEfficiencyTable",
data: JSON.stringify({
firstName :firstName;
customerId : customerId;
}),
success: function (data) {
document.getElementById('dvFirstName').innerHTML = data.data[0].Name;
document.getElementById('dvStartDate').innerHTML = data.data[0].StartDate;
},
fail: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
},
FirName看起来很完美,但对于StartDate,它将显示为/ Date(123456789)/。
任何想法?
我尝试过:
1.尝试在线搜索但没有得到任何线索。
The "FirName" appear perfectly but for "StartDate", it would be displayed as /Date(123456789)/.
Any ideas?
What I have tried:
1. Tried to search online but without getting any clues.
推荐答案
.ajax({
contentType: application / json; charset = utf-8,
dataType : json,
type: POST,
url: / Customer / LoadRecordsForEfficiencyTable,
data: JSON .stringify({
firstName:firstName;
customerId :customerId;
}),
成功s: function (data){
document .getElementById(' dvFirstName')。innerHTML = data.data [ 0 ]。名称;
document .getElementById(' dvStartDate').innerHTML = data.data [ 0 ]。StartDate;
},
失败: function (jqXHR,textStatus,errorThrown){
alert(errorThrown);
},
错误: function (jqXHR,textStatus,errorThrown){
alert(errorThrown);
}
});
},
.ajax({ contentType: "application/json; charset=utf-8", dataType: "json", type: "POST", url: "/Customer/LoadRecordsForEfficiencyTable", data: JSON.stringify({ firstName :firstName; customerId : customerId; }), success: function (data) { document.getElementById('dvFirstName').innerHTML = data.data[0].Name; document.getElementById('dvStartDate').innerHTML = data.data[0].StartDate; }, fail: function (jqXHR, textStatus, errorThrown) { alert(errorThrown); }, error: function (jqXHR, textStatus, errorThrown) { alert(errorThrown); } }); },
FirName看起来很完美,但对于StartDate,它将显示为/ Date(123456789)/。
任何想法?
我尝试过:
1.试图在线搜索但没有得到任何线索。
The "FirName" appear perfectly but for "StartDate", it would be displayed as /Date(123456789)/.
Any ideas?
What I have tried:
1. Tried to search online but without getting any clues.
试试这个
try this
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [year, month, day].join('-');
}
document.getElementById('dvStartDate').innerHTML = formatDate(new Date(parseInt(data.data[0].StartDate.substr(6))));
这篇关于除了字符串数据类型之外,Html无法正确显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!