【问题标题】:GET Method PlayGET 方法播放
【发布时间】: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


【解决方案1】:

你需要定义路线

GET     /plots                                       Application.plots(id:Long)

$.get("/plots", id, function(${list})

或根据您的代码

*       /{controller}/{action}                  {controller}.{action}

使用

 $.get("Application/plots", id, function(${list}){ //Application is your controller name

但我会建议使用第一个

【讨论】:

  • 我收到以下错误: SyntaxError: missing variable name ...get("/plots", id, function([Sample[3982], Sample[3983], Sample[3984], Sa ...
猜你喜欢
  • 1970-01-01
  • 2012-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-05
  • 2013-05-13
  • 2018-11-21
相关资源
最近更新 更多