【发布时间】:2016-09-17 17:24:46
【问题描述】:
如果我在路由器的 post("/some") 路径中有 Future[A] 作为结果(最后一行),则 Ajax 客户端无法获得响应并超过超时。等待不起作用。 Future onComplete/onSuccess {...} 工作正常,但是对于服务器,那么如何将其作为响应翻译给客户端呢? (Scalatra 框架)
服务器:
post("/stations/test") {
Future[Int] {
// parse jsonData ...
Thread.sleep(3000)
1
}.onComplete { x =>
// do something on server ...
}
}
客户:
@JSExport
def testFuture() = {
val request = Ajax.post("/stations/test", jsonData)
}
【问题讨论】:
标签: ajax scala future scalatra