Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Coldfusion error - Unable to add text to HTML HEAD tag

Posted on 2015-01-13
19
Medium Priority
?
845 Views
Last Modified: 2015-01-27
Unable to add text to HTML HEAD tag.
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.

I have a page that needs to add js to the head.  I'm using the cfhtmlhead tag.  If I don't use the cfhtmlhead tag, the code doesn't work.  If I use the tag I get the above error message.  The error occurs on the Ajax call to get a list of individuals.  If I use Firefox dev tools I can see the error in the basic.cfc code.

<cfsavecontent variable="SaveDateStuff">

<script type="text/javascript">
	$(document).ready(function() {

	CloseGrid=function(){
		$("#userslistdiv").pqGrid('destroy');
		$('#userslistdiv').hide;
	}

    ListUsers=function(em) {
        var emid = em.title;
        $('#userslistdiv').show();

        var colM = [
            { title: "IndivID", width: 100, dataType: "integer", editable: false},
            { title: "Lastname", width: 150, dataType: "string", editable: false },
            { title: "Firstname", width: 150, dataType: "string", editable: false }
        ];
        var dataModel = {
            location: "remote",
            dataType: "JSON",
            method: "GET",
            paging: 'local',
            rPP:15,
            rPPOptions:[15, 30, 45],
            getUrl : function () {
                return { url: 'cfc/basic.cfc?method=getIndivs&EmID=' + emid};
            },
            getData: function ( response ) {
                return { data: response.DATA };
            }
        	}
        $.extend(colM[0], {
        	render: function (ui) {
           		var rowData = ui.rowData; ;
               	return "<a href='<cfoutput>#request.controlUrl#</cfoutput>individuals/index.cfm?fa=viewIndiv&indivnum=" + rowData[0] + "' target='_blank'>" + rowData[0] + "</a>";
            }
    	});
        $("#userslistdiv").pqGrid({ width:458, height:470, title:"List of Emailer Individuals for " + emid, dataModel: dataModel, colModel: colM, scrollModel:{horizontal: false}, flexHeight: true });
            //alert("it worked-" + emid);
    };

});

</script>
</cfsavecontent>
<cfhtmlhead text="#SaveDateStuff#">

<cfloop query="qpages">
      <tr>
	<td>#qPages.id#</td>
	<td><a href="index.cfm?fa=edit&eid=#qPages.id#" class="black anchorclass">#qPages.name#</a></td>
	<td>#qPages.create_name#</td>
	<td>#val(qEmailerSends.sent_count)#</td>
	<td>#qEmailerViews.recordCount#</td>
	<td>#qPages.service_id#</td>
	<td>#dateformat(qPages.date_last_run, "yyyy/mm/dd")#</td>
	<td><input name="SeeUsers" id="SeeUsers" class="SeeUsersButton" value="See Users" type="button" title="#qPages.id#" onclick="ListUsers(this);"></td>
   </tr>
</cfloop>

Open in new window



If I add up the size of all elements in the page I get 1700kb.  I changed the maximum buffer size to 2056 and 4096.  No difference.

I'm using PQgrid to show the list of users.  This all worked on the CF9 server.  We recently migrated to CF10 on a new Windows 2012 server.
0
Comment
Question by:lanterv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 5
  • 3
19 Comments
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 40552160
after cfflush tag, you cannot use the  cfhtmlhead. here is the doc:

Because the cfflush tag sends data to the browser when it executes, it has several limitations, including the following:

    Using any of the following tags or functions on a page anywhere after the cfflush tag can cause errors or unexpected results: cfcontent, cfcookie, cfform, cfheader, cfhtmlhead, cflocation, and SetLocale. Similarly, do not use any tags that use AJAX features, including cfdiv, cflayout, cflayoutarea, cfpod, cfsprydataset, cftooltip, cfwindow, or HTML format cfgrid, cftree, cftextarea, or cfinput (using autosuggest or datefield attributes) tags. All of the preceding tags and functions normally modify the HTML header, but cannot do so after a cfflush tag, because the cfflush sends the header.
    Using the cfset tag to set a cookie anywhere on a page that has a cfflush tag does not set the cookie in the browser.
    Using the cfflush tag in the body of several tags, including cfsavecontent, cfquery, and custom tags, causes errors.
    If you save Client variables as cookies, any client variables that you set after a cfflush tag are not saved in the browser.
0
 

Author Comment

by:lanterv
ID: 40552176
I'm not using the cfflush tag.
0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 40552362
please check if anywhere above in the header cfflush is being used, there is a bug of cfhtmlhead in cf11 but in cf10 it works fine
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Author Comment

by:lanterv
ID: 40552609
There is no cfflush in any code file on the entire site.
0
 

Author Comment

by:lanterv
ID: 40552785
I did a workaround and got rid of cfhtmlhead tag.  I get the same error message but it points to this tag;
<cfajaximport tags="cfform, cfdiv, cfgrid">
0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 40552890
can u please close the tag like this:

<cfajaximport tags="cfform, cfdiv, cfgrid" />
0
 

Author Comment

by:lanterv
ID: 40553894
Still getting same error.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40564488
Can you post a small, stand-alone example? Putting together an independent script will help in two ways a) ensure it's not something in the page causing the problem AND b) give us a runnable example we can test.
0
 

Author Comment

by:lanterv
ID: 40564689
The error seems to trigger on a call for this function;

	<cffunction name="getIndivs" access="remote" returntype="query" HINT="Get All Resources" returnFormat="JSON">
		<cfargument name="emID" required="True" default="0">
    	<cfquery name="get_Indivs" datasource="#request.dsn#">
        	SELECT ui.id, ui.lastname, ui.firstname
        	FROM emailers_userid_ab_maps as e left join
				users_info as ui on ui.id = e.userid
			where e.emailer_id = #val(arguments.emid)#
        	ORDER BY ui.lastname, ui.firstname
    	</cfquery>
    	<CFRETURN get_Indivs>
	</cffunction>

Open in new window


I'm just not seeing the problem.
0
 

Author Comment

by:lanterv
ID: 40564730
This is the Jquery that calls that function;

<script type="text/javascript">
	$(document).ready(function() {

	CloseGrid=function(){
		$("##userslistdiv").pqGrid('destroy');
		$('##userslistdiv').hide;
	}

    ListUsers=function(em) {
        var emid = em.title;
        $('##userslistdiv').show();

        var colM = [
            { title: "IndivID", width: 100, dataType: "integer", editable: false},
            { title: "Lastname", width: 150, dataType: "string", editable: false },
            { title: "Firstname", width: 150, dataType: "string", editable: false }
        ];
        var dataModel = {
            location: "remote",
            dataType: "JSON",
            method: "GET",
            paging: 'local',
            rPP:15,
            rPPOptions:[15, 30, 45],
            getUrl : function () {
                return { url: 'cfc/basic.cfc?method=getIndivs&EmID=' + emid};
            },
            getData: function ( response ) {
                return { data: response.DATA };
            }
        	}
        $.extend(colM[0], {
        	render: function (ui) {
           		var rowData = ui.rowData; ;
               	return "<a href='#request.controlUrl#individuals/index.cfm?fa=viewIndiv&indivnum=" + rowData[0] + "' target='_blank'>" + rowData[0] + "</a>";
            }
    	});
        $("##userslistdiv").pqGrid({ width:458, height:470, title:"List of Emailer Individuals for " + emid, dataModel: dataModel, colModel: colM, scrollModel:{horizontal: false}, flexHeight: true });
            //alert("it worked-" + emid);
    };

});

</script>

Open in new window

0
 

Author Comment

by:lanterv
ID: 40564746
And this is the line of code that's referred to in the error message;

<cfajaximport tags="cfform, cfdiv, cfgrid" />

Open in new window

0
 

Author Comment

by:lanterv
ID: 40564984
Is there a way to grant you access to the page without posting the criteria to the public?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40565559
EDIT:

>> And this is the line of code that's referred to in the error message;

I don't see that anywhere in the code posted.

We need to run the same code you're using on your end. Since it's probably part of a larger script, can you just create a minimal test page with only the grid and the cfajaximport? Just enough to reproduce the error.  (Don't worry about the getIndivs() function. I can create a dummy function for that part.)


You should be able to send individual messages via:
http://www.experts-exchange.com/myMessages.jsp
0
 

Author Comment

by:lanterv
ID: 40565613
The problem comes in when the page is built.  We use a quasi fusebox action.  There are a few cfincludes in the process.  I'll see what I can do about simplifying the code a bit.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40565675
Before your last message, I'd created a test page ... hoping to reproduce the error. But it worked fine w/CF10. Maybe it'll give you something to work with?  The only thing changed was the CFC path.

Test.cfm
<!--- add to see if it has any effect --->
<cfajaximport tags="cfform, cfdiv, cfgrid" />

<!--- create dummy variables for testing ONLY --->
<cfset request.controlUrl = "somePage.cfm">
<cfset qpages = queryNew("")>
<cfset queryAddColumn(qpages, "ID", [1,2,3])>
<cfset queryAddColumn(qpages, "Name", ["Name1","Name2","Name3"])>


<cfsavecontent variable="SaveDateStuff">
<script type="text/javascript">
	$(document).ready(function() {

	CloseGrid=function(){
		$("#userslistdiv").pqGrid('destroy');
		$('#userslistdiv').hide;
	}

    ListUsers=function(em) {
        var emid = em.title;
        $('#userslistdiv').show();

        var colM = [
            { title: "IndivID", width: 100, dataType: "integer", editable: false},
            { title: "Lastname", width: 150, dataType: "string", editable: false },
            { title: "Firstname", width: 150, dataType: "string", editable: false }
        ];
        var dataModel = {
            location: "remote",
            dataType: "JSON",
            method: "GET",
            paging: 'local',
            rPP:15,
            rPPOptions:[15, 30, 45],
            getUrl : function () {
                return { url: 'mycfc.cfc?method=getIndivs&amp;EmID=' + emid};
            },
            getData: function ( response ) {
                return { data: response.DATA };
            }
        	}
        $.extend(colM[0], {
        	render: function (ui) {
           		var rowData = ui.rowData; ;
               	return "<a href='<cfoutput>#request.controlUrl#</cfoutput>individuals/index.cfm?fa=viewIndiv&amp;indivnum=" + rowData[0] + "' target='_blank'>" + rowData[0] + "</a>";
            }
    	});
    	
        $("#userslistdiv").pqGrid({ width:458, height:470, title:"List of Emailer Individuals for " + emid, dataModel: dataModel, colModel: colM, scrollModel:{horizontal: false}, flexHeight: true });
            //alert("it worked-" + emid);
    };

});

</script>
</cfsavecontent>


<!DOCTYPE html>
<html lang="en">
<head>	
	<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/base/jquery-ui.css" />    
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
	<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
	<link class="link-override" rel="stylesheet" href="http://paramquery.com/Content/css/themes/Office/pqgrid.css" />
	<link rel="stylesheet" href="http://paramquery.com/Content/css/pqgrid.min.css" />    
	<script src="http://paramquery.com/Content/js/touch-punch.js"></script>
	<script src="http://paramquery.com/Content/js/pqgrid.min.js"></script> 
	<cfhtmlhead text="#SaveDateStuff#">
</head>
<body>
	<a href="javascript:CloseGrid()">Close</a>
	
	<!--- minimal code to display grid --->
	<table>
	<cfoutput query="qpages">
	    <tr>
		<td>#qPages.name#</td>
		<td><input name="SeeUsers" id="SeeUsers" class="SeeUsersButton" value="See Users" type="button" title="#qPages.id#" onclick="ListUsers(this);"></td>
	   </tr>
	</cfoutput>
	</table>
	
	<!--- for pqGrid --->
	<div id="userslistdiv"></div>
	
	<!--- deliberately generate LOTS of elements to increase size of page ---->
        <cfoutput>
	<cfloop from="1" to="50000" index="x">
		<div id="ThisServesNoPurpose#x#">#x#<div>
	</cfloop>
        </cfoutput>
</body>
</html>

Open in new window


MyCFC.cfc

<cfcomponent> 
	
	<cffunction name="getIndivs" access="remote" returntype="query" HINT="Get All Resources" returnFormat="JSON">
		<cfargument name="emID" required="True" default="0">
		
		<cfset Local.qry = QueryNew("ID,LastName,FirstName")>
		
		<cfloop from="1" to="10" index="Local.x">
			<cfset Local.row = queryAddRow(Local.qry, 1)>
			<cfset Local.qry.ID[Local.row] = Local.x>
			<cfif Local.x eq arguments.emID>
				<cfset Local.qry.LastName[Local.row] = "*** LastName "& Local.x>
			<cfelse>
				<cfset Local.qry.LastName[Local.row] = "LastName "& Local.x>
			</cfif>
			<cfset Local.qry.FirstName[Local.row] = "FirstNameame "& Local.x>
    	</cfloop>
	
    	<cfreturn Local.qry />
	</cffunction>
	
</cfcomponent>

Open in new window

0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 40565711
I have to head out. I'll check back tomorrow.
0
 

Author Comment

by:lanterv
ID: 40573956
The solution was to add;

<cfif NOT listLast("#cgi.CF_TEMPLATE_PATH#", ".") eq "CFC">

around the code in my OnRequestEnd.cfm so cfc calls won't cause html to be added to the output.
0
 

Author Closing Comment

by:lanterv
ID: 40573961
Thank you so much for sticking with this problem.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40574058
You're welcome. Glad we finally figured out the cause!
0

Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question