Playframework 如何整理以下播放框架路由?
我试图按照“介绍游戏框架”中的示例进行操作。到目前为止,我已经在这里部署了工作 例如,当我搜索IPad时,它会显示“凌乱”的URL 我认为我在conf/routes中的路由设置是正确的,因为当我使用“clean”URL时,它会得到正确的结果 我不知道如何让我的表单显示干净的URL。原始HTML是Playframework 如何整理以下播放框架路由?,playframework,Playframework,我试图按照“介绍游戏框架”中的示例进行操作。到目前为止,我已经在这里部署了工作 例如,当我搜索IPad时,它会显示“凌乱”的URL 我认为我在conf/routes中的路由设置是正确的,因为当我使用“clean”URL时,它会得到正确的结果 我不知道如何让我的表单显示干净的URL。原始HTML是 <div id="searchdiv"> <form action="@{Application.search()}" method="GET"> <
<div id="searchdiv">
<form action="@{Application.search()}" method="GET">
<input type="text" id="search" name="search" />
<input type="submit" id="submit" name="submit" value="Search" />
</form>
</div>
非常感谢您对我需要更改的内容的任何帮助。如果需要,routes文件如下所示
GET /listing/create Application.createAuctionItem
POST /listing/create Application.doCreateItem
GET /listing/show/{id} Application.show
GET /listing/show Application.show
GET /search/{search} Application.search
GET /search Application.search
GET / Application.index
提交按钮中不需要名称。否则,它将作为表单的参数发送。 放 我想应该没问题。 您需要将表单中的URL与在routes中指定的URL匹配。 使用jQuery的一个可能的解决方案如下所示:
<script type="text/javascript>
$(document).ready(function(){
$('#searchdiv form').submit(function(e){
e.preventDefault();
// not a good design though, once you change the route to Application.search,
// this will failed
this.attr('action', '/search/'+$('input#search').val());
this.submit();
});
});
</script>
顺便说一下,Application.search中的参数数量与表单不匹配。这可能是另一个问题
<input type="submit" id="submit" value="Search" />
<script type="text/javascript>
$(document).ready(function(){
$('#searchdiv form').submit(function(e){
e.preventDefault();
// not a good design though, once you change the route to Application.search,
// this will failed
this.attr('action', '/search/'+$('input#search').val());
this.submit();
});
});
</script>