What I am doing is getting data from the database using ajax and displaying it in html text fields for update purposes. Below is my web method code where I get the data from successfully.
[WebMethod] public static List<Employee> getEmployee() { var slist = new List<Employee>(); var db = new BLUEPUMPKINEntities(); slist = db.Employees.ToList(); return slist; }
Now, when I get data from a database, I got a date in this format /Date(725828400000)/ . I am looking for google about parsing and converting json date string format to html / javascript date also use third-party plugins like moment.js and jquery.ui, but does not solve my problem. Also here I am sharing my code, from which I get data from ajax in json format and display it on jquery datatable.
$.ajax({ url: "Employees.aspx/getEmployee", data: null, contentType: "Application/json; charset=utf-8", responseType: "json", method: "POST", success: function (response) { //alert(response.d); var jsonObject = response.d; var result = jsonObject.map(function (item) { //var date = new Date(item.EMP_DOB); //var obj = Date.parse(date); var result = []; result.push(''); result.push(item.EMP_FNAME); result.push(item.EMP_MNAME); result.push(item.EMP_LNAME); result.push(item.EMP_EMAIL); result.push(item.EMP_DOB); //this is my date column in my database from where date is in yyyy/mm/dd format result.push(item.EMP_USERNAME); result.push(item.EMP_PASSWORD); result.push(item.ID); return result; }); myTable.rows.add(result); // add to DataTable instance myTable.draw(); }, error: function (xhr) { alert(xhr.status); }, Failure: function (response) { alert(response); } });
I need a date in the format mm / dd / yyyy. Please help me solve my problem.
Ahmer Ali Ahsan
source share