2015/10/19 Summary: Ajax pass, jquery.validate custom date Check

Source: Internet
Author: User

The following content only comes from the daily practice piecemeal review, summary, not guarantee correctness, welcome to pass the Great God pointing guidance!

1, these days have been writing JSP front-end page, to understand the front-end and back-end data interaction data there are two kinds. One is the submission of a form, which can be submitted in a form by declaring a property: Method = ' Post ' declaring the form submission (to correspond to the Requestmethod property of the controller in the background), action = ' The URL ' declares a page that jumps after the form has been submitted (as if this were the usual way to jump to the page). Another way is through the AJAX submission, the AJAX submission and response data is in JSON format, because AJAX is asynchronous data request, do not jump page, so the controller in the background corresponding to the method also annotated annotated @responsebody; bootstrap Table's data interaction with the background is in the form of Ajax, except that the bootstrap table package is better, and the URL, the parameters of the request, and the parameter of the response are used directly.

Two types of requests are understood:

GET: The argument is spelled after the URL address. The sign begins,& stitching; generally used for the submission of small amounts of form data;

POST: The application of the data in the HTTP message body, generally used for a large number of submissions;

2, because of the basic use of jquery validate, today directly fencing to get a form in the input starting date can not be greater than the expiration date of the check, probably browsed the tutorial in the Runoob on the Internet to find some demo knocked in, encountered a variety of problems, including the calibration did not respond, JS file is not available, check the information does not come out and so on, now think, is the heart too urgent, plus a variety of grammar unfamiliar with the trouble. There are many well-packaged checksum methods in jquery validate that can be used directly in HTML or JS, but there seems to be no ready-made way to find the requirements. Decide to add a custom check method, referring to an example on the Internet as follows:

$.validator.addmethod ("Comparedate", function (value,element) {
var assigntime = $ ("#assigntime"). Val ();
var deadlinetime = $ ("#deadlinetime"). Val ();
var reg = new RegExp ('-', ' G ');
Assigntime = Assigntime.replace (Reg, '/');//Regular replacement
Deadlinetime = Deadlinetime.replace (Reg, '/');
Assigntime = new Date (parseint (Date.parse (assigntime), 10));
Deadlinetime = new Date (parseint (Date.parse (deadlinetime), 10));
if (assigntime>deadlinetime) {
return false;
}else{
return true;
}
}, "<font color= ' #E47068 ' > End date must be greater than the start date </font>");

The procedure is described as follows:

1. Convert the standard time to a timestamp by using the Date.parse () method to process.

2. Convert the timestamp to an integer to ensure that it is handled by parseint ("", 10) in case of an event.

3. Convert the timestamp to the Date object new Date (). After the object is converted, you can compare the time size

bOK choy, according to the plot of urine development, the story is often not so smooth, the problem came, can not use Ah, pit dad ah. During the course of the year, I ran over 10 million grass mud horses.

The result of the last toss is: 1) to add the jquery validate citation file;

2) Date control plus <input class= "Comparedate" >

3) to trigger the check after the date control has left the focus, add $ ("#form") to the JS file. Validate ();

Finally, there are bugs, bugs, bugs ... The comparison of the date in the check is actually the date of the control hit (or last) value, I use the date control for Bootstrap-datetimepicker, do not know whether it is the problem of the program, or the problem of the date control, hope that the useful God can tell one or two ....

    

2015/10/19 Summary: Ajax pass, jquery.validate custom date Check

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.