Cause Analysis and Solution for failure to submit forms using the submit method in JS and jQuery, jquerysubmit

Source: Internet
Author: User

Cause Analysis and Solution for failure to submit forms using the submit method in JS and jQuery, jquerysubmit

Yesterday, when I made a form to asynchronously submit content, I encountered a very strange problem. The submit () method could not be submitted, and the current packet was refreshed every time I submitted it, every time the get method is used to get the current page, there is no post request. I think this is because the name or id in the form conflicts with the submit, but after checking several times, no name conflict is found, so this possibility is ruled out.

I usually do the trigger button by myself. I basically don't need the tag, but I didn't know what the problem was yesterday. I actually used a and gave the href blank. Because the class of a has multiple contents, therefore, no href content is read during the check. Therefore, the href = "" operation is triggered every time the click operation is performed. This operation re-opens the current page, so the submit cannot be used. Solution: Add javascript:; or javascript: void (0) to href );

Where the problem occurs:

Solved:


Js section:

Supplement: differences between js form submission and submit submission

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

Note:When the get method is used to submit a form, values cannot be transmitted using url in the action, and values can be transmitted using post.

Differences between js submission and submit button submission:

1. When submitting a form in js, the value of the submit button is not included (because it is not clicked) in all browsers.

2. input and press enter to submit the w3c browser. The value of the submit button is not included in ie6.

Solution: Add a hidden domain and use this to determine whether or not to submit the data.

Bind a submission event on the submit button:

That is:

Copy codeThe Code is as follows:
<Input type = "submit" name = "btn" value = "btn" onclick = "test ()"/>

Will carry the value of submit, and the onsubmit status cannot be detected when submitting with js.

W3c: submit once

Ie6: submitted twice. js submitted in form first

Solution:If the button is submit, the onsubmit event is used for detection.

If the button is a button, the submit event is triggered after the detection succeeds.

Do not use js to submit the form, and then use onsubmit to detect

Simply use js to submit a form. alert and ff will block the submission of the form.

The above section describes the reason why JavaScript and jQuery cannot submit forms using the submit method and the related knowledge about the solution. I hope this will help you, if you have any questions, please leave a message and the editor will reply to you in time. Thank you very much for your support for the help House website!

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.