I'm taking my first crack at Ajax with jQuery. 我正在使用jQuery在Ajax上進行首次嘗試。 I'm getting my data onto my page, but I'm having some trouble with the JSON data that is returned for Date data types. 我正在將數據存儲到頁面上,可是爲Date數據類型返回的JSON數據遇到了一些麻煩。 Basically, I'm getting a string back that looks like this: 基本上,我獲得的字符串看起來像這樣: json
/Date(1224043200000)/
From someone totally new to JSON - How do I format this to a short date format? 從徹底不熟悉JSON的人-如何將其格式化爲短日期格式? Should this be handled somewhere in the jQuery code? 是否應該在jQuery代碼中的某個地方處理? I've tried the jQuery.UI.datepicker
plugin using $.datepicker.formatDate()
without any success. 我已經嘗試使用$.datepicker.formatDate()
嘗試使用jQuery.UI.datepicker
插件,但沒有成功。 this
FYI: Here's the solution I came up with using a combination of the answers here: 僅供參考:這是我結合如下答案使用的解決方案: spa
function getMismatch(id) { $.getJSON("Main.aspx?Callback=GetMismatch", { MismatchId: id }, function (result) { $("#AuthMerchId").text(result.AuthorizationMerchantId); $("#SttlMerchId").text(result.SettlementMerchantId); $("#CreateDate").text(formatJSONDate(Date(result.AppendDts))); $("#ExpireDate").text(formatJSONDate(Date(result.ExpiresDts))); $("#LastUpdate").text(formatJSONDate(Date(result.LastUpdateDts))); $("#LastUpdatedBy").text(result.LastUpdateNt); $("#ProcessIn").text(result.ProcessIn); } ); return false; } function formatJSONDate(jsonDate) { var newDate = dateFormat(jsonDate, "mm/dd/yyyy"); return newDate; }
This solution got my object from the callback method and displayed the dates on the page properly using the date format library. 該解決方案從回調方法中獲取了個人對象,並使用日期格式庫在頁面上正確顯示了日期。 .net