Java重定向在Flask中不起作用

问题描述 投票:0回答:1

我正在建立一个Flask网站,并试图创建一个始终位于顶部菜单中的搜索栏,我希望在Python后端中进行处理,但是如果不包括每个支持的文本,我将无法找到一种方法页面上的代码来处理它(如果这是唯一的方法就可以了),所以我决定尝试使其与JavaScript一起使用。这是我的代码(没有发现与问题无关的部分):

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type="search" id="searchbar"/>
<button id="goto">Search</button>
<script>
            document.getElementById("goto").addEventListener("click", goTo);
            function goTo()
            {
                var result = document.getElementById("searchbar").value;
                window.location.href = "/users/"+result;
            }
</script>
</body>
</html>

应该执行的操作是将我重定向到“ http://myip/users/WhatItyped”,而只添加“ /?”。到网址末尾,为什么会这样?

更新:我发现,如果我在定义结果之前添加警报,它将起作用

javascript html
1个回答
0
投票

尝试使用window.location.pathname

© www.soinside.com 2019 - 2024. All rights reserved.