fre*_*shp 2 javascript json typo3 fluid extbase
我试图在javascript变量中获取json.我在我的extbase typo3-extension中使用了fluid-templates.在我的动作中,我加载了一些卷曲的json.这个json我分配给模板.在我的模板中,它看起来像:
<script type="text/javascript">
var json = {jsonVarFromControllerAction};
</script>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,json被解释为html代码.看起来像:
{"content":"testcontent"}
Run Code Online (Sandbox Code Playgroud)
在控制器动作中它是一个正确的json!
{"content": "testcontent"}
Run Code Online (Sandbox Code Playgroud)
什么是解决方案?
使用<f:format.htmlentitiesDecode>ViewHelper对其进行解码,例如:
<script type="text/javascript">
var json = <f:format.htmlentitiesDecode>{jsonVarFromControllerAction}</f:format.htmlentitiesDecode>;
</script>
Run Code Online (Sandbox Code Playgroud)
您可以浏览所有可用的ViewHelpers typo3/sysext/fluid/Classes/ViewHelpers
其他选项是直接从使用AJAX的动作获取使用PHP格式化的JSON(不将其传递给视图)如果您想要在不刷新整个页面的情况下获取新数据,这将非常有用.
| 归档时间: |
|
| 查看次数: |
3365 次 |
| 最近记录: |