我創建了一個 api,它將從我的數據庫中搜索數據。它的工作原理如下:localhost://12345/api/example/search/userinput。我想將其集成到我的前端中,為此我在 html 文件中編寫了以下代碼<input type="search" placeholder="Search TradeId" name="input"><button onclick="document.location = 'api/example/search/input'" class="btn btn-primary navbar-btn" >Search Trade</button>但它所做的是搜索我的數據庫中的“輸入”,而不是我輸入的值。可以說我必須搜索約翰,但它正在搜索輸入。
2 回答

飲歌長嘯
TA貢獻1951條經驗 獲得超3個贊
也許是這樣的:
<button onclick="document.location = 'api/example/search/input?' + document.getElementById('input').value" class="btn btn-primary navbar-btn" >Search Trade</button>
但是你的 API enpoint 是“/input”還是“/userinput”?

蝴蝶不菲
TA貢獻1810條經驗 獲得超4個贊
可以通過編寫腳本來解決
<script>
function myFunction(){
var x = document.getElementById("myinput").value;
var q = location.href;
var y = "api/example/search/";
var t = q+y+x;
location.assign(t);
}
</script>
<input type="search" placeholder="Search TradeId" id="myinput">
<button onclick="myFunction()" class="btn btn-primary navbar-btn" >Search Trade</button>
- 2 回答
- 0 關注
- 136 瀏覽
添加回答
舉報
0/150
提交
取消