Home > Article > Web Front-end > Analysis of the difference between button and submit in jQuery ajax
<script type="text/javascript"> $(document).ready(function(){ $("#submit").click(function(){ $.post("sendPwd.php",{QQnum:$("#QQnum").val(),psw:$("#psw").val()},function(data){ $("#aaa").html(data); },"html"); }); }); </script>
It should be no problem to write the post method of jQuery ajax like this. Click the submit button, sendPwd.php receives the passed value through $_POST, and then echoes a piece of data. However, the returned value cannot be displayed. The reason is here:
<input type="submit" name="submit" id="submit" value="提交" />
The type of the submit button is submit, and there is no response after clicking it. Because I accidentally discovered that the result came out once I clicked it, and then changed back, I found it strange. I checked online and found that most of the buttons were set to button type, so after changing it to button, the problem was solved.
Button What is the difference between button and submit?
Submit is mainly used to submit the form. It is a special button that performs the submission action. The button is mainly operated with JavaScript and is itself a button. This is the fundamental difference. If you want to use submit, verification needs to return false. I think it is more convenient to set it as a button.
For more related articles on the analysis of the difference between button and submit in jQuery ajax, please pay attention to the PHP Chinese website!