aru*_*nov 1 ajax scala url-routing playframework-2.0
我正在尝试javascriptRoutes在Play 2(Scala)中使用,我收到错误(见下文).这是我做的:
javascriptRoutes方法到Application控制器def javascriptRoutes = Action { implicit request =>
import routes.javascript._
Ok(Routes.javascriptRouter("jsRoutes")(Orders.searchProducts))
.as("text/javascript")
}
Run Code Online (Sandbox Code Playgroud)
routes文件GET /assets/javascripts/routes controllers.Application.javascriptRoutes
Run Code Online (Sandbox Code Playgroud)
<script>导入到main.scala.html<head>
...
<script type="text/javascript" src="@routes.Application.javascriptRoutes"></script>
...
</head>
Run Code Online (Sandbox Code Playgroud)
有了这些更改,我在JavaScript控制台中收到以下错误:
GET http://localhost:9000/assets/javascripts/routes 404 (Not Found)
Uncaught ReferenceError: jsRoutes is not defined
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
小智 6
conf/routes文件中的错误顺序可能会导致问题.
有一个提示:
http://grokbase.com/t/gg/play-framework/1348rbs2vk/2-1-scala-javascript-router-404
一旦我根据提示调整了订单:
将javascript路由器操作的路由定义移动到资产路由之上.
问题是固定的.
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
GET / controllers.MainController.index()
GET /message controllers.MessageController.getMessage()
GET /assets/javascripts/routes controllers.MessageController.javascriptRoutes()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
GET /webjars/*file controllers.WebJarAssets.at(file)`
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2074 次 |
| 最近记录: |