Home > Web Front-end > JS Tutorial > body text

Analysis of the difference between button and submit in jQuery ajax

高洛峰
Release: 2017-01-11 11:36:36
Original
1066 people have browsed it

<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>
Copy after login

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="提交" />
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!