R.Quintal
R.Quintal

Reputation: 53

button acting strange and reloads the page

I've created a button in this context: enter image description here

And I have a javascript function expecting the click to make a request to the server: enter image description here

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: enter image description here

enter image description here

Upvotes: 1

Views: 46

Answers (2)

Marcel Ennix
Marcel Ennix

Reputation: 1366

Try insert: type="button" inside the button tag. Otherwise it will be a submit button (when inside a form tag).

Upvotes: 1

Stasel
Stasel

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

Related Questions