How to redirect after submitting form

Mitarano

I'm new to Javascript and Svelte and I'm trying to redirect after submitting a form. I've tried many things, but the goto function seems to be the only thing that even tries to load the redirected page. Unfortunately I get the following error message. Why does it happen?

500
Unexpected token < in JSON at position 0

Here is my code:

<script>
    import { goto } from '$app/navigation';

    let title;
    let description;
    let images;

    async function submitForm() {
        const dataArray = new FormData();
        dataArray.append("title", title);
        dataArray.append("description", description);
        dataArray.append("image", images[0]);

        const submit = await fetch("new.json", {
            method: "post",
            body: dataArray
        })

        const data = await submit.json();
        // do something with data

        goto("/");
    }
</script>
Aravind D

use window.location.href = "http://stackoverflow.com"; to get redirect

window.location.href = "http://stackoverflow.com";

Collected from the Internet

Please contact javaer1[email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to redirect user after submitting form with React

How to redirect website after submitting google form?

How to redirect after submitting form in php

How to redirect on submitting a form?

How to redirect to another HTML page after submitting a form?

How do I redirect users after successfully submitting form data?

How to prevent redirect after submitting data through a form

How to redirect confirmation page after submitting form in Laravel?

PHPMAILER, how to redirect to the thank you page after submitting the form?

Redirect to other view after submitting form

redirect to another page after submitting a form

Trying to redirect in PHP after submitting an email form

Django Form after redirect is empty after successfully submitting a form

How can I redirect to a new page after submitting a form using Jinja template?

How to redirect to newly created document page after submitting the form firestore for web

How to redirect to List View Page in PHP CodeIgniter using parameters after submitting a form?

How to redirect to a new page using an object id after submitting a form in Django?

"redirect" function of django is not and after submitting the form, user remains on same page

redirect List<Data> to a view after user has submitting a form

Redirect user to specific url after submitting the edit account address form

React Router redirect after submitting a form using the input value

Want to redirect to the URL after successfully submitting the form JS

Redirect to contacts page after submitting form in laravel 4

Redirect to function based detail view after submitting form

How to clean a form with stars in javascript after submitting?

How to get a popup box after submitting a form?

How to clean form after submitting ajax?

How to display alert message after submitting form

How to reset the form in React after submitting?