在rails中基于javascripts on / off处理HTML和JS请求
When user turn off JavaScript then follow HTML request flow otherwise follow JS request flow.
当用户关闭JavaScript时,请遵循HTML请求流,否则请遵循JS请求流程。
HTML flow means : request as html => render html template => response as HTML ( when JavaScript off in browser )
HTML流意味着:请求为html => render html template =>响应为HTML(当浏览器中的JavaScript关闭时)
JS flow means : request as JS => render JS template => response as JS ( when JavaScript on in browser )
JS流意味着:请求JS =>渲染JS模板=>响应为JS(当浏览器中的JavaScript时)
I have one solution for that and that is :-
我有一个解决方案,那就是: -
I have to write code to handle both request in my all controller something like this :
我必须编写代码来处理我的所有控制器中的这两个请求:
respond_to do |format| format.html format.js end
I have to create both type of template js and html and render common data in it.
我必须创建两种类型的模板js和html并在其中呈现公共数据。
But in above solution, i think there is very much duplicate code like we have to write respond_to code in every controller and we have to create two copy of every page (js.html, erb.html).
但是在上面的解决方案中,我认为有很多重复的代码,比如我们必须在每个控制器中编写respond_to代码,我们必须创建每个页面的两个副本(js.html,erb.html)。
So i need standard solution(if any) to handle both kind of request based on JavaScript enabled/disable in browser without any duplication.
所以我需要标准的解决方案(如果有的话)来处理基于JavaScript启用/禁用的两种请求,而不需要任何重复。
1 个解决方案
#1
0
You only need to create this block for methods that need to respond to js calls - normally these are ajax methods, and not every method in your application.
您只需要为需要响应js调用的方法创建此块 - 通常这些是ajax方法,而不是应用程序中的每个方法。
Are you really doing everything in your application by ajax? Or just a select few methods?
您是否真的通过ajax在您的应用程序中执行所有操作?或者只是选择几种方法?
更多相关文章
- 使用jquery在textarea中的颜色代码
- 为什么我的javascript/jquery代码不能像预期的那样工作?
- 实现浮动广告的代码
- 豆瓣Javascript代码风格规范
- 【问题解决方案】ImportError: No module named 'pygal'
- Python 黏包及黏包解决方案
- 计算机视觉相关代码片段(Python)
- 120行python代码解锁10000分微信跳一跳
- XGBoost中参数调优的完整指南(含Python-3.X代码)