我正在提交一个表单,其中有一些复杂的嵌套到Rails控制器.Java语言与提交"按钮绑定在一起,如下所示:
I'm submitting a form, with somewhat complex nesting to a Rails controller. The Javascript is tied to the submit button as below:
$('#new_search').submit(function() { var valuesToSubmit = $(this).serializeArray(); $.ajax({ type: "POST", url: $(this).attr('action'), //sumbits it to the given url of the form data: valuesToSubmit, dataType: "POST" }) return false; // prevents normal behaviour });Rails控制器可以很好地处理这些参数,并且所有参数都应在其应有的位置.
The Rails controller handles this fine and the parameters are all where they should be.
然后我渲染一个js.erb文件:
I'm then rendering a js.erb file:
respond_to do |format| format.js { render '/searches/update_search_results.js.erb' } end并且日志显示确实已渲染:
and the log shows this has indeed rendered:
Rendered searches/update_search_results.js.erb (0.3ms)但是在这个文件中(我已经仔细检查了文件名),甚至是一个简单的
But in this file (I've doubled checked the file name) even a simple
alert("hello world");没有开火.控制台日志中没有Javascript错误.任何人有任何建议吗?与发送Ajax请求的原始Java脚本有关系吗?谢谢你的帮助
is not firing. There are no Javascript errors in the console log. Anyone got any suggestions? Something to do with the original Javascript that sends the Ajax request? thanks for any help
推荐答案好,通过在视图的表单定义中返回旧样式:remote => true来解决此问题.
OK, fixed it by going back to the old style :remote => true in the form definition in the view.
我认为世界已经从这个问题转移到了毫不夸张的JS提交事件.显然我错了,但是此解决方案可能会对某人有所帮助,所以我将其留在这里
I thought the world had moved away from this to unobtrusive JS bouncing off the submit event. Obviously I was wrong but this solution might help someone so I'm leaving it here
更多推荐
Rails js.erb无法正常工作
发布评论