Introduction:
I have a WebMethod
on my ASP.NET page which returns a Person
object.
One of the fields is Birthday
which is a DateTime
property.
WebMethod
[WebMethod]
public static Person GetPerson()
{
Person p = new Person() {
Id = 1,
Name = "Test",
Birthday = new DateTime(1988, 9, 13)
};
return p;
}
If I make the call using $.ajax()
I get the response of the server with the Person
object.
Ajax call
// Class instance
var Ajaxcalls = function () {
}
_$.extend(Ajaxcalls, {
GetPerson: function (label) {
var self = label instanceof _$ ? label : $(label);
_$.ajax({
url: 'Default.aspx/GetPerson',
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
console.log(JSON.stringify(data.d));
self.html(new Date(Date.parse(data.d.Birthday)));
}
});
}
});
Result:
{"__type":"AjaxTest.Classes.Person","Id":1,"Name":"Test","Birthday":"/Date(590104800000)/"}
Problem
How do I parse the Birthday
[/Date(590104800000)/] to a javascript/jQuery date?
I tried new Date(Date.parse(data.d.Birthday))
but it gives me an Invalid date
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…