Can successfully submit the form I created but then I'm sent a json export page.

Daniel Baron September 6, 2018

 

I created a form in a html macro that's designed to update other Confluence pages. When I click the form button the other Confluence pages are successfully updated but the browser then navigates to this json export page. From looking at the dev tools it seems like something is timing out setTimeout (see attached screenshot below). Is there a way I can figure out what's wrong with my code so I can prevent this from happening? Thanks for any help.

 

Screen Shot 2018-09-06 at 11.22.24 AM.png

1 answer

0 votes
Zak Laughton
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 13, 2018

Hi Daniel,

JSON responses like that are typical of Confluence REST API responses. Since you are getting a JSON response after pushing the button, it seems as though the button is taking the form data and submitting it to the browser as an API request.

This type of page redirection can be expected from any <input> or <button> element with type="submit" (which may be the default type, depending on the browser). Exactly how the data is submitted in HTML forms depends on how the form is set up (see MDN - Sending Form Data), but basically it can boil down to undesired redirection when all you want your button to do is run a script.

If you want to execute the page changes from the script without redirecting to another page, you'll likely need to stop the button from running it's default submit behavior. In my personal experience, I've had success doing this by using Event.preventDefault() at the beginning of whatever script I want my button to trigger.

If that doesn't work, there are some great alternatives and discussion about this type of issue on this Stack Overflow post: Stop form refreshing page on submit.

I hope this helps!
-Zak

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events