【发布时间】:2018-10-16 14:11:05
【问题描述】:
我正在尝试将旧的 Play 2 Framework 应用更新到最新版本 2.6.19
一个视图使用 Post Query Ajax 将表单发送到控制器,但现在更新代码后,表单中绑定的数据始终为空(“无”)。
如果我使用文档并编写 ScalaForm,数据会到达,但我不知道是否可以将脚本与 Scala Form Helpers 混合使用,因为我需要在提交之前和之后执行一些操作。
我怀疑问题可能是过滤器或application.conf中的某些东西,无法成功绑定数据。
我使用的是 jquery 1.11.2
这是我在旧版本中使用但现在不起作用的代码。
观点:
<form method="post" id="entrarLTerme">
<h4>Término Actual:</h4>
<p class="redex" contenteditable="true" id="ent" spellcheck="false"></p>
<button id="accepta" type="submit" value="val">@messages.messages("tilcgfs.entrar")</button>
</form>
<script>
$("#entrarLTerme").submit(function (e) {
uncheck();
var formURL = $(this).attr("action");
var aux = $("#ent").text();
$.ajax(
{
url: formURL,
type: "POST",
data: {valor: aux, op: "0", pag: "2"},
success: function (data) {
// Call some JS functions
}
},
error: function () {
// Call some JS functions
}
});
e.preventDefault();
});
</script>
和控制器:
class TilcWT @Inject()(component: ControllerComponents, instanciesTilcWT: InstanciesTilcWT,langs: Langs) extends AbstractController(component) with I18nSupport {
implicit var messages: Messages = MessagesImpl(Lang("ca"), messagesApi)
val opcionsDefinicions = Form(
tuple(
"valor" -> text,
"op" -> text,
"pag" -> text))
def opcions = Action { implicit request =>
val usuari: String = request.session.get("user").get
opcionsDefinicions.bindFromRequest.fold(
formWithErrors => {
BadRequest("Not Alloweddd")
},
options => {
val valor = options._1
val opt = options._2
val page = options._3
BadRequest("Not Alloweddd")
}
)
BadRequest("Not Allowed")
}
}
在我使用折叠功能之前,我“得到”了这个,没有任何问题。调试器正确到达“opcions”方法,当然 BadRequest 是虚拟的。
我的 application.conf 如下所示:
# The application languages
# ~~~~~
play.i18n.langs=["en","ca","es"]
play.filters.enabled=[]
提前致谢
【问题讨论】:
-
日志中有什么可以帮助理解的吗?