Home >Web Front-end >JS Tutorial >Why Does My AngularJS Button in a Form Cause a Page Refresh?
AngularJS Button Within Form Triggers Page Refresh
This issue arises when you have a form with both a submit button and a navigation button. Upon clicking the navigation button, AngularJS initiates a page refresh, resulting in a 404 error.
The reason behind this problem is that the navigation button is assumed to be a submit button by default in AngularJS, unless explicitly marked otherwise. To resolve this, you can mark the navigation button as type='button', as per the W3C specification:
<button>
This ensures that the button does not trigger a form submission when clicked, preventing the page refresh.
The above is the detailed content of Why Does My AngularJS Button in a Form Cause a Page Refresh?. For more information, please follow other related articles on the PHP Chinese website!