Home > Web Front-end > JS Tutorial > A quick solution to the problem that Ajax submits the Form form page and still refreshes

A quick solution to the problem that Ajax submits the Form form page and still refreshes

亚连
Release: 2018-05-23 10:32:20
Original
2051 people have browsed it

This article mainly introduces the quick solution to the problem that the Ajax form page will still refresh when submitting the Form form, and when there is a button in the form form, it will automatically refresh after the Ajax submission. Question, friends who need it can refer to

After a long time, I clicked the submit button and added a type="button" It turned out to be <form > <button id ="sub" /> </form> No matter how you do it, the page will be refreshed, just add it

PS: When there is a button in the form, after the ajax submission Automatic refresh problem

<form class="form-horizontal">
<p class="form-group">
<label class="col-sm-3 control-label">修改资料名称:</label>
<p class="col-sm-7"> <input type="text" placeholder="test22" class="form-control"></p>
<p class="col-sm-2">
<button class="btn btn-primary" onclick="resetCertificateName(14)">修改</button>
</p>
</p>
</form>
Copy after login

When there is a button tag in the form, the page will be refreshed after asynchronously submitting the form using ajax. (It feels very weird)

Cause: When the button exists, the form will be submitted again, so the page is refreshed. (Previously thought button type='submit' ) button has the function of submitting the form.

Solution: Just replace the button label with a label. <a class="btn btn-primary" onclick="resetCertificateName(14)">Modify</a>

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future. help.

Related articles:

AJAX display loading and pop-up layer occlusion page implementation example

Tongda OA uses Ajax Use the workflow plug-in to add OA accounts based on human resources system data (detailed graphic and text explanation)

How to use ajax to submit forms in the Lavarel framework_AJAX related

The above is the detailed content of A quick solution to the problem that Ajax submits the Form form page and still refreshes. For more information, please follow other related articles on 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