The submitHandler commit of the jQuery validate plug-in leads to an endless loop solution. jqueryvalidate is submitted.

Source: Internet
Author: User

The submitHandler commit of the jQuery validate plug-in leads to an endless loop solution. jqueryvalidate is submitted.

This article describes the solution to the endless loop caused by submitHandler submission of the jQuery validate plug-in. We will share this with you for your reference. The details are as follows:

The dom submits form. submit (); and jquery submits $ (''). submit ();. There is no difference in the function. However, if the jquery validate plug-in is used, the two are significantly different during submission. $ (''). When submit () is submitted, jquery validate is verified. If $ ('') is written in submitHandler (''). submit (); will lead to an endless loop, while form. submit (); then no.

This problem is a small problem. If you do not pay attention to it or get used to it, it is easy to make mistakes. In case of errors, it is difficult to find out. It took me nearly two hours to find the reason.

I. Briefly describe dom and jquery

Dom object. You need to write JavaScript code to operate the object, tag in the page. For jquery, you must use the jquery syntax.

It is also very easy to convert a dom object to a jquery object. Just add $ (), and then you can use the jquery syntax to operate the object. I think this is the most common use. Let's take a look at the example.

$ ('Input [name ^ = "hour"] '). each (function (index) {this. value = index; // this is a dom object, js format}); $ ('input [name ^ = "hour"] '). each (function (index) {$ (this ). val (index); // $ (this) is a jquery object, written in jquery });

Ii. jquery validate endless loop Program

$("#product_form").validate({  focusInvalid:false,  submitHandler: function(form){    $('.submit').submit();  }});

Correct writing,

$("#product_form").validate({  focusInvalid:false,  submitHandler: function(form){    form.submit();  }});

When an endless loop occurs, the browser will remain in the loading State until the Browser fails. At this time, you can add an alert and you will know that validate is continuously in the loop verification process. I personally think that although it is a small problem, it is hard to remember.

Related Article

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.