JS time format

Source: Internet
Author: User
Tags button type error status code

Title, Ajax requests to get JSON data to populate the HTML page, encountered a time cannot format the problem.

Because it is JS, the FMT tag reference is invalid, the web also searched many JS time formatted functions are invalid.

Since spring MVC was used to think of annotations, the way to do this is to use annotations on the application's Entity class Time field:

@DateTimeFormat (pattern = "YYYY-MM-DD hh:mm:ss")//annotations can inject time in this format
@JSONField (format = "Yyyy-mm-dd hh:mm:ss") //default format converted to by Ajax JSON parsing
Private date uptime;//shelf time ',

Then the JS page does not need to deal with:
Get a paging function
function GetPage (obj,num,info) {
$.ajax ({
Type: "GET",//Request type
url:path+ "/getcardspage",//URL of the request
Data: {id:obj,index:num,info:info},//request parameter
DataType: "JSON", the data type returned by the//ajax interface (request URL)
Async:false,//true asynchronous, false synchronous
Success:function (data) {//data: Return data (JSON object)
$ ("#storyBooksssss"). HTML ("");
var div = "";
for (var i = 0; i < data.newList.length; i++) {
div+= "<div class=\" product_storylist_content_left\ "></div>" +
"<div class=\" product_storylist_content_right\ "><ul>" +
"<li class=\" product_storylist_content_dash\ "><a href=\" #\ "class=\" blue_14\ ">" +data.newList[i].gName + "</a></li>" +
"<li> Customer Rating: </li> ' +
"<li> Rated Rate:" + data.newlist[i].praiserate + "%</li>" +
"<li> Point Card Name:" + data.newlist[i].cname + "</li>" +
"<li> Shelf Time:" + data.newlist[i].uptime + "</li>" +
"<li>" + data.newlist[i].cinfo + "</li>" +
"<li><dl class=\" product_content_dd\ "> <dd>&nbsp;&nbsp;</dd>" +
"<dd><a href=" +path+ "/static/tocardview/" + data.newlist[i].cid + "/" +data.newlist[i].gid+ ">" +
"</a></dd>" +
"<dd class=\" footer_dull_red\ "><span> actual price: ¥" +data.newlist[i].price+ "</span></dd>" +
"<dd class=\" product_content_delete\ "><span> original price: ¥" +data.newlist[i].iniprice+ "</span></dd > "+
"</dl> </li> </ul> </div><div class=\" product_storylist_content_bottom\ "></div > ";
}
div+= "<input type= ' hidden ' id= ' totalpagecount ' value=" +data.totalpagecount+ ">";

$ ("#storyBooksssss"). html (div);
$ ("#pageNo"). HTML ("");
$ (". Page-bar"). Remove ();//error point, you must add this sentence to clear
var page= "<div class= ' Page-bar ' >" +
"<p class= ' Page-num-ul ' >" +
"<span>&nbsp;&nbsp; Total" +data.totalcount+ "records </span>" +
"<span>&nbsp;&nbsp;" +data.currpageno+ "/" +data.totalpagecount+ "page </span>";
if (data.currpageno>1) {
page+= "<a href=\" javascript:;\ "id= ' 1 ' class= ' first ' >&nbsp;&nbsp; home </a>" +
"<a href=\" javascript:;\ "class= ' pre ' id= '" + (data.currpageno-1) + "' >&nbsp;&nbsp; prev </a>";
}
if (Data.currpageno < Data.totalpagecount) {
page+= "<a href=\" javascript:;\ "class= ' Next ' id= '" + (data.currpageno+1) + ">&nbsp;&nbsp; next </a> "+
"<a href=\" javascript:;\ "class= ' last ' id= '" +data.totalpagecount+ "' >&nbsp;&nbsp; final page </a>";
}
page+= "<span class= ' page-go-form ' ><label>&nbsp;&nbsp; jump to </label>" +
"<input type= ' text ' name= ' inputpage ' id= ' inputpage ' class= ' page-key '/> page" +
"<button type= ' button ' class= ' page-btn ' id= ' page-btn ' >GO</button>" +
"</span></p></div>";
$ ("#pageNo"). HTML (page);
},
Error:function (data) {//when accessing, 404,500 not 200 error status code
Alert ("Load paging information failed!") ");
}
});
}
Effect:



JS time format

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.