Link to home
Start Free TrialLog in
Avatar of lanterv
lanterv

asked on

Coldfusion error - Unable to add text to HTML HEAD tag

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.
Avatar of Coast Line
Coast Line
Flag of Canada image

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.
Avatar of lanterv
lanterv

ASKER

I'm not using the cfflush tag.
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
Avatar of lanterv

ASKER

There is no cfflush in any code file on the entire site.
Avatar of lanterv

ASKER

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">
can u please close the tag like this:

<cfajaximport tags="cfform, cfdiv, cfgrid" />
Avatar of lanterv

ASKER

Still getting same error.
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.
Avatar of lanterv

ASKER

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.
Avatar of lanterv

ASKER

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

Avatar of lanterv

ASKER

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

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

Open in new window

Avatar of lanterv

ASKER

Is there a way to grant you access to the page without posting the criteria to the public?
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:
https://www.experts-exchange.com/myMessages.jsp
Avatar of lanterv

ASKER

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.
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

ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lanterv

ASKER

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.
Avatar of lanterv

ASKER

Thank you so much for sticking with this problem.
You're welcome. Glad we finally figured out the cause!