Problem description:
Front-end page
<Input type = "button" class = "inputbutton" id = "btnlogin" value = "login"/>
Show. JS:
$("#btnlogin").click(function(){ $.ajax( { url : "LoginAction", type:"post", dataType:"json", data:"username="+userName, timeout:20000, success:function(){} });});
When you click log on, data will be submitted again. Think twice!
Cause analysis:
After reading the analysis from netizens, some said, "the reason for the two submissions is that after the Ajax request is executed, the submit action is not blocked, the solution is not to use the button with the type of submit, but to use the button with the type of button. "However, I use the button with the type = button. Therefore, the reason is excluded. Some netizens said this was a jquery bug. After testing, similar methods were also used on other pages of the program I wrote. This did not happen, so the reason was also ruled out.
After some exploration, I finally found the cause:
I include (top. jsp) on this page (login. jsp), and show. JS is introduced in both pages:
<script type="text/javascript" src="js/show.js"></script>
This leads to the introduction of the show. js file twice, so the file will be submitted twice. In the top. jsp file
<script type="text/javascript" src="js/show.js"></script>
This phenomenon does not occur after deletion. This is a perfect solution!
This mistake reminds me that you must be careful when writing code later.