简体   繁体   English

重定向/重新加载页面而不是控制器中的js.erb

[英]redirecting/reloading page in js.erb instead of controller

My index.js.erb is refreshing the page only partially: 我的index.js.erb仅部分刷新页面:

$("#view").html("<%= escape_javascript render 'view' %>");

I am able to refresh it fully in the controller with this line: 我可以使用以下代码在控制器中完全刷新它:

format.js { render :js => "window.location.replace('#{url_for(:controller => :view, :action => :index, :some_parameter => value)}');" }

Is it possible to refresh the page in js.erb? 是否可以在js.erb中刷新页面?

edit: I call index.js.erb by this command in the controller: 编辑:我通过控制器中的此命令调用index.js.erb:

format.js { redirect_to(:action => :index, :format => :js, :some_parameter => value)}, 

It refreshes the page with the content for some_parameter, but refreshes it only partially. 它使用some_parameter的内容刷新页面,但仅部分刷新。

window.location works better, but I read in one of stack overflow posts that it is better to use erb than controller for javascript. window.location效果更好,但我读过一篇堆栈溢出文章,其中说说,使用erb比使用javascript控制器要好。 Is it really? 是不是真的?

第二种方法是刷新整个页面(发出另一个http请求),如果要执行此操作,为什么不使用redirect_to呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM