Yesterday, when making a form to submit content asynchronously, encountered a very strange problem, submit () method can not be submitted, each submission is the current to refresh, network grab bag found, each time is get way to obtain the current page, there is no POST request, think of the previous encounter such a problem is because The name or ID in the form has a conflict with submit, but it has been checked several times and there is no conflict of names, so this possibility is excluded.
Usually do the trigger button, basically do not use a label, but yesterday did not know what the problem, unexpectedly used a and returned to the href is empty, because of this a class has multiple content, so the inspection time did not go to see href did not write content. Therefore, every time the click operation will trigger to href= "" This operation, the operation will reopen the current page, so that the submit can not play a role. Workaround: Add javascript to href:; or javascript:void (0);
Where the problem occurs:
Solved:
JS section:
Add: The difference 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 a Get method submits a form, the action cannot use a URL to pass the value, and the post can pass
The difference between JS submission and submit button submission:
1. JS submits the form without the value of the Submit button (because it is not clicked) all browsers
2. Input carriage return submission The Web browser will bring the value of the Submit button, IE6 will not bring
Solution: Add a hidden domain, use this to judge, no matter which way commit will have a value
Submit button Bind Commit event:
That
Copy Code code as follows:
<input type= "Submit" Name= "BTN" value= "btn" onclick= "Test ()"/>
will bring the value of submit, with JS submission are not detected onsubmit state
The Consortium: Submit once
IE6: two times submitted, first JS in form Submit
Workaround: If the button is submit, detect with onsubmit event
If the button is a buttons, after the test is passed, the submit event is triggered
Must not use JS to submit the form, and then use onsubmit to detect
Simply use JS to submit the form, alert, FF blocking the form's submission, while other browsing
The above is a small set to introduce JS and jquery using Submit method can not submit form analysis and solve the reasons for the relevant knowledge, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!