Processing of jquery/Asp.net MVC datetime

Source: Internet
Author: User
Tags dateformat

Datetime in Javascript needs to use new date (318326400000). The JSON time format returned by Asp.net MVC is/date (318326400000 )/
 
The date type of JSON data consumed by the jquery. Ajax () function can be added through jquery. Ajax. datafilter in jquery 1.2.6 or later versions.

Step 1: Use the datafilter function of jquery. Ajax () to pre-process the Asp.net datetime object to a local JavaScript Object.
$. Ajax ({
Type: "Post ",
Datatype: "JSON", // data format: JSON
URL: '/myproject/searchmailinfojson', // target address
Data: "page =" + pageindx + buildwhere (),
Beforesend: function () {$ ("# divload"). Show (); $ ("# pagination"). Hide () ;}, // before sending data
Complete: function () {$ ("# divload"). Hide (); $ ("# pagination"). Show () ;}, // The data has been received
Datafilter: function (data, type ){
Return data. Replace (/"\\\/ (date \ ([0-9-] + \) \\\/"/GI, 'new $1 ');
},
Success: function (JSON ){
$ ("# List-Table TR: GT (0)"). Remove ();
$. Each (JSON, function (I, item ){
If (item ["sendtime"] = NULL ){
Item ["sendtime"] = "";
}
VaR TRS = "";
TRS + = "<tr style = 'font-weight: '> <TD align = 'center'>" + item ["emailsubject"];
TRS + = "</TD> <TD align = 'center' style = 'word-wrap: Break-word; Word-break: Break-all; '> ";
TRS + = item ["messageto"] + "</TD> <TD>" + item ["messagefrom"] + "</TD> ";
TRS + = "<TD align = 'left'>" + item ["emailcc"] + "</TD> <TD align = 'center'>" + item ["mailtype "] +" </TD> ";
TRS + = "<TD align = 'center'>" + dateformat (item ["arriveddatetime"], "yyyy-mm-dd hh: mm: SS ") + "</TD> ";
TRS + = "<TD align = 'center'>" + item ["status"] + "</TD> ";
TRS + = "<TD align = 'center'>" + dateformat (item ["sendtime"], "yyyy-mm-dd hh: mm: SS ") + "</TD> ";
TRS + = "<TD> <a href = 'javascript: showpopwin ('effect preview', 'sendmailpreview? Sysid = "+ item [" systemid "] +" & mailid = "+ item [" ID "] +" ', 600,600, null, true, true);> preview </a> </TD> <tr> ";
Tbody + = TRS;
});

$ ("# List-table"). append (tbody );

$ ("# List-Table TR: GT (0)"). Hover (function (){
$ (This). addclass ('mouseover ');
}, Function (){
$ (This). removeclass ('mouseover ');
});
}
});
Step 2 process the string representation of the date in Javascript, similar to. Net datetime. tostring (). This can use another JavaScript time format library, see the http://blog.stevenlevithan.com/archives/date-time-format

Http://www.overset.com/2008/07/18/simple-jquery-json-aspnet-webservice-datetime-support/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.