【发布时间】:2015-07-10 09:00:41
【问题描述】:
我在 Play Framework 1.3.x 中有一个控制器,我在其中定义了以下内容:
public static void plots(Long id) {
//... (Code goes here)
render(list); //Data to render
}
然后在视图文件夹中的一个单独的 html 文件中,我想“显示”另一个 html 文件的结果。我正在尝试通过以下方式做到这一点:
<script type="text/javascript">
setInterval(function() {
$.get("plots", id, function(${list}){ //I want to give the list needed by the file plots.html
$("#result").html(list); //And then in "result" show the plots obtained
})
}, 1000);
</script>
...
<span id="result"></span>
但它根本不显示任何内容。这个绘图文件只需要这个列表,然后对数据进行绘图,但我很确定我没有以正确的方式编写代码,我的意思是,我没有为函数提供正确的语法或参数。有任何想法吗?谢谢!
PS:我的路线文件
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / Application.index
# Ignore favicon requests
GET /favicon.ico 404
# Map static resources from the /app/public folder to the /public path
GET /public/ staticDir:public
# Catch all
* /{controller}/{action} {controller}.{action}
【问题讨论】:
-
确保在 HTML 头标签中包含 jquery
-
我认为你的问题是 URL 对 jQuery 无效。
"plots"对他来说是未知的,并且不是有效的 URL。我想你需要看看反向路由playframework.com/documentation/1.3.x/routes#reverse -
这是我的路由文件:# Routes # 这个文件定义了所有应用程序路由(优先级较高的路由)# ~~~~ # Home page GET / Application.index # Ignore favicon requests GET /favicon. ico 404 # 将 /app/public 文件夹中的静态资源映射到 /public 路径 GET /public/ staticDir:public # Catch all * /{controller}/{action} {controller}.{action}
-
好吧,我最好编辑我的帖子并将它们写在那里以便更好地阅读它们。
标签: javascript java plot playframework get