skip to Main Content

I got problem.

When I choose image file, file is sending to server, but when it finish I don’t see alert but new blank page.

How to fix it?
Here is script

async function AJAXSubmit(oFormElement) {
    fetch(oFormElement.action)
        .then((response) => {
            if (response.status === 200) { alert("ok") }
        });
 }

2

Answers


  1. The issue most probably occurs because the form is being submitted in the traditional way (default form submission behavior), which reloads the page.

    You should use event.preventDefault() to prevent default submission behaviour.

    async function AJAXSubmit(oFormElement) {
        // Prevent the form from submitting in the default way
        event.preventDefault();
    
        your code comes here
    
    Login or Signup to reply.
  2. Use event.preventDefault() before implementing your code and this should solve your issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search