有没有一种方法可以防止cfchart将js强制放入响应内容中? [英] Is there a way to prevent cfchart from forcing js into response content?

查看:92
本文介绍了有没有一种方法可以防止cfchart将js强制放入响应内容中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:报告了错误,对此投票表示赞赏 https://tracker.adobe.com/#/view/CF-4200017

Update: reported bug, votes appreciated https://tracker.adobe.com/#/view/CF-4200017

我们正在从ColdFusion 10迁移到2016年.看来,兼容性方面的唯一障碍是制图系统的更改.对于整页请求,这通常很好,但是在某些情况下,我们会生成png格式的图表,捕获所生成的内容,并去除一些同时生成的js,并将结果返回json作为页面更新的一部分.我们遇到的一个问题是CF强制将请求响应中的javascript与输出的实际内容分开,从而导致json响应无效.

We are migrating from ColdFusion 10 to 2016. It appears the only hurdle with compatibility is the change in charting system. For full page requests this is generally fine but in some spots we generate a chart in png format, capture the content generated and strip out some js that is generated simultaneously and return the result in json as part of a page update. A problem we are running into is that CF is forcing javascript in the request response separate from the actual content being output causing json responses to be invalid.

似乎正在使用cfhtmlhead标记之类的方法插入js,在该方法中查找head标记的响应,如果找到则在其中插入代码,否则只会将代码添加到整个请求中.对于应该为json的响应,这显然是一个问题.

It seems the js is being inserted using an approach like the cfhtmlhead tag where it looks in the response for head tags, inserts code there if found, otherwise it just prepends the code to the entire request. For a response that should be json this is obviously a problem.

我已经尝试在图表生成之前调用刷新,但是随后出现错误"ColdFusion无法将您指定的文本添加到输出流.这可能是因为您已经在模板中使用了CFFLUSH标记或已将其缓冲cfchart代码被点击时关闭输出.

I already tried calling a flush before the chart generates but then I get the error "ColdFusion was unable to add the text you specified to the output stream. This is probably because you have already used a CFFLUSH tag in your template or buffered output is turned off" when the cfchart code is hit.

关于如何告诉CF内联代码或以其他方式重置计划插入到请求输出中的内容的任何建议?

Any suggestions on how to tell CF to put the code inline or otherwise reset the content planned for insertion into the request output?

示例:

<cfsavecontent variable="ignore">
<cfchart format="png">
    <cfchartseries type="Bar" label="Numbers">
        <cfchartdata item="First" value="1">
        <cfchartdata item="Second" value="2">
    </cfchartseries>
</cfchart>
</cfsavecontent>

<cfcontent reset="true" />
test

结果:

<script type="text/javascript">/* <![CDATA[ */_cf_loadingtexthtml="<img alt=' ' src='/cf_scripts/scripts/ajax/resources/cf/images/loading.gif'/>";
_cf_contextpath="";
_cf_ajaxscriptsrc="/cf_scripts/scripts/ajax";
_cf_jsonprefix='//';
_cf_websocket_port=8579;
_cf_flash_policy_port=1243;
_cf_clientid='1D0DA2C606EC323ABBECA5B29A016CF0';/* ]]> */</script><script type="text/javascript" src="/cf_scripts/scripts/ajax/messages/cfmessage.js"></script>
<script type="text/javascript" src="/cf_scripts/scripts/ajax/package/cfajax.js"></script>
<script type="text/javascript" src="/cf_scripts/scripts/chart/cfchart-server.js"></script>

test

对于cfdocument标记中使用的图表,这甚至是一个问题(只需将cfsavecontent标记替换为cfdocument filename ="test.pdf"进行测试).将该图表添加到磁盘上的文档中,然后js在请求响应中输出,从而终止了旨在恢复下载链接和其他数据的ajax请求.

It is even an issue for charts used in cfdocument tags (just replace the cfsavecontent tags with cfdocument filename="test.pdf" to test). The chart gets added to the document on disk but then js gets output in the request response, killing our ajax requests that are meant to bring back the download link and other data.

推荐答案

可以使用以下两个选项之一来解决此问题:重置CF自动插入到<head>中的内容:

This can be addressed with either of the following options for resetting the content that CF inserts automatically into the <head>:

<cfcontent reset="true" resethead="true">

<cfset getPageContext().getCFOutput().clearHeaderBuffers()>

这些方法尚未记录(因此有可能在将来的版本中进行更改,尽管可能性不大),并且这些方法不太可能移植到其他CFML引擎中.

These approaches are not documented (so possible to change in future version -- though unlikely) and these approaches are unlikely to be portable to other CFML engines.

这篇关于有没有一种方法可以防止cfchart将js强制放入响应内容中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆