jquery page refresh not working when cfc function has a <cfinclude>
Part of my app provides various email content pages, which are called and populated with data, then prepared for sending through Postmark.
In the following case, when a user shows interest in a job, s/he clicks a button labelled "Chase Job" which ultimate results in an email being sent to the job owner.
When that button is clicked, jQuery handles it as follows:
$('#chase-form .btnChase').on("click",function(e){
var clickedID = $(this).attr("id");
var chase = clickedID.split("_")[1];
var user_id = clickedID.split("_")[2];
var listing_id = clickedID.split("_")[3];
var message = $('#intro-message').val();
$(this).prop('disabled', true);
jQuery.getJSON("/cfcs/listing.cfc?method=chaseJob&returnformat=json",{"chase":chase,"user_id":user_id,"listing_id":listing_id,"status":status,"message":message},function(res,code){
if(res == 1){
top.location.reload(true);
}
$('#chase-form .btnChase').removeAttr("disabled");
});
return true;
});
This hits a function in listing.cfc
<cffunction name="chaseJob" access="remote" returnType="any">
....
<cfset res = variables.oUser.SendJobStatusEmail(
sender_id=arguments.user_id,
recipient_id=qListing.user_id,
status=arguments.status,
listing_id=arguments.listing_id,
userType=0)>
....
<cfreturn res>
</cffunction>
This, in turn, calls a function in user.cfc
<cffunction name="SendJobStatusEmail" access="remote" returnType="any">
... compile some data for an email ...
<!---The following generates a page of html and wraps it in <cfsavecontent>. That <cfsavecontent> is made available to the function by including it here. However, if I do it this way, processing doesn't reach the jQuery page reload --->
<cfinclude template="/email-templates/template.cfm">
<!---Instead of the above, if I hardcode some html, it DOES allow processing to reach the jQuery reload --->
<cfset emailBody='<div> <p>Hi there</p> <div>'>
....
<cfreturn 1>
Contents of the included template as follows:
<cfsilent>
...
<!--- set variables accessible by the email template, etc --->
...
<cfset page_upload_path = entity_upload_path & "\" & vListingID>
<!--- create the page dir --->
<cfif not directoryexists(page_upload_path)>
<cfdirectory directory="#page_upload_path#" action="create">
</cfif>
<!--- load template into savecontent variable. --->
<cfsavecontent variable="page_content">
<cfinclude template="template-chase-homeowner.cfm">
</cfsavecontent>
<!--- A populated version of the template is now available via "page_content" --->
<!--- upload the rendered template, to be called later into an email --->
<cfset randNo = createUUID()>
<cfset vFile = "#page_upload_path#\#randNo#.cfm">
<cffile action = "write"
file = "#vFile#"
output = "#page_content#"
nameconflict = "overwrite">
</cffile>
</cfsilent>
<!--- fetch the rendered page and wrap it in cfsavecontent --->
<cfsavecontent variable = "emailBody">
<cfinclude template="#viewFile#">
</cfsavecontent>
<!--- "emailBody" is the variable used for the Postmark API call --->
Further processing inside user.cfc simply sends an email
<cfset resPostmark = oSystem.sendPostmarkEmail(
mailHtml = emailBody
... other parameters ...
)>
Can anyone help in understanding the issue, i.e.: Presenting the data inside a cfc using a <cfinclude>, while it works in sending a perfect email, somehow balks the processing, so that it never reaches the jQuery callback directing the page to reload.
