Javascript 从Play获取带有参数的url
这很有效:Javascript 从Play获取带有参数的url,javascript,jquery,scala,playframework,playframework-2.2,Javascript,Jquery,Scala,Playframework,Playframework 2.2,这很有效: <script type="text/javascript"> $(".class1" ).click(function() { window.location.href = "@routes.MyController.index()"; //OK }) </script> $(“.class1”)。单击(函数(){ window.location.href=“@routes.MyController.index()”;//确定 })
<script type="text/javascript">
$(".class1" ).click(function() {
window.location.href = "@routes.MyController.index()"; //OK
})
</script>
$(“.class1”)。单击(函数(){
window.location.href=“@routes.MyController.index()”;//确定
})
但这并不是:
<script type="text/javascript">
$(".class1" ).click(function() {
window.location.href = "@routes.MyController.show(_: Int)" + getCurrentIdFromHiddenField();
});
</script>
$(“.class1”)。单击(函数(){
window.location.href=“@routes.MyController.show(@Int:Int)”+getCurrentIdFromHiddenField();
});
因为,“@routes.MyController.show(\uquot:Int)”
返回一个部分应用的函数
我不想硬编码
url
,我想以某种方式获取它 您可以使用Play的Javascript路由器:
您必须生成jsRoutes
对象,说明在文档中
jsRoutes.controllers.MyController.show(getCurrentIdFromHiddenField())