表单提交后重定向到新页面

时间:2020-08-30 13:34:05

标签: javascript

提交表单后如何重定向到另一个页面。这是我的代码:

    form.addEventListener("submit", function (e) {
        e.preventDefault;
        
        console.log("sasadas")

        mal = {
            "omkrets": form.omkrets.value,
            "areal": form.areal.value,
            "hoyde": form.hoyde.value,
        }

        document.cookie = 'mal=' + JSON.stringify(mal) + ";domain=;path=/";
        window.location.href = "http://127.0.0.1:8000/kategori/";
    })

我尝试过window.location.href,但是不起作用。有任何想法吗?我搜寻了一下,但没有找到明确的答案。

1 个答案:

答案 0 :(得分:2)

只需更换

e.preventDefault;

使用

e.preventDefault();