Reputation: 53
I've created a button in this context:
And I have a javascript function expecting the click to make a request to the server:
But something weird happens when I hit the button, the page reloads it all and don't take the action expected. Thank you all in advance, im gettin crazy with this.
When I put an alert to check if the button is triggered I get an error:
Upvotes: 1
Views: 46
Reputation: 1366
Try insert: type="button" inside the button tag. Otherwise it will be a submit button (when inside a form tag).
Upvotes: 1
Reputation: 1298
There is a chance that you get this behavior because of the form
tag. Try to remove the form tag and try again.
Maybe this can also help you: Stop form refreshing page on submit
Upvotes: 2