![](/img/trans.png)
[英]Hide submit button on form_tag in ruby on rails with js/jquery
[英]Ruby on Rails 2.3, form_tag submitted to Rails controller, JS function not called
当前设置:Ruby on Rails 2.3和Ruby 1.8.7(不要问...我们正在努力)。
在引导程序模式中使用form_tag helper来调用Rails控制器中的操作。 这是视图(.haml)
- form_tag({:action => 'update_logins'},
{:method => :post, :multipart => true, :id => 'upload_form', :target => 'upload_target', :class=>'form-horizontal' })
控制器动作已正确调用,但是我正在返回对Javascript函数的调用,尽管进行了多次尝试,但它没有调用该函数,而是呈现了文本。 甚至控制器中的一个简单的render语句也不起作用: render :js => "alert('hello');"
我觉得这与请求标头似乎不接受javascript有关:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
响应标头指示Javascript: Content-Type:text/javascript; charset=utf-8
Content-Type:text/javascript; charset=utf-8
并正确接收到响应: alert('hello');
但是实际上无法成功调用任何函数。
有任何想法吗?
我假设您正在使用SLIM / HAML来模板化引擎。 检查您是否在HTML中生成<form>
标记
你可以尝试更换
- form_tag({:action => 'update_logins'},{:method => :post, :multipart => true, :id => 'upload_form', :target => 'upload_target', :class=>'form-horizontal' })
至
= form_tag({:action => 'update_logins'},{:method => :post, :multipart => true, :id => 'upload_form', :target => 'upload_target', :class=>'form-horizontal' })
这样,它将在您的html中创建一个<form>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.