admin管理员组

文章数量:1123233

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") }
        });
 }

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") }
        });
 }

Share Improve this question asked 10 hours ago BogdanBogdan 72 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 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

Use event.preventDefault() before implementing your code and this should solve your issue.

本文标签: javascriptFetch Api redirect to pageStack Overflow