I have created a CFC to process and return comments posted back to the submitting page. It just returns a JSON string of the comment made back to the browser which is then inserted into the DOM using jQuery.
However, I also want to send an email to notify the author that a new comment has been posted. I want to do this AFTER the JSON has been returned to the browser because it will speed up the user interface than having to wait for an email to be sent before updating the DOM.
I am currently testing this and can't see that ColdFusion will execute anything after a <cfreturn>
tag. For example the following is not working for me:
<cffunction>
....
<cfreturn NewComment/>
<!--- Anything after the cfreturn above doesn't seem to get executed --->
<cfmail to="[email protected]" from="[email protected]">
A new comment is available for you to read
</cfmail>
</cffuntion>
However this DOES work:
<cffunction>
....
<cfmail to="[email protected]" from="[email protected]">
A new comment is available for you to read
</cfmail>
<cfreturn NewComment/>
</cffuntion>
What's the deal with this and how could I achieve what I'm trying to do? If I wanted to do a whole lot more than just send an email then the DOM would have wait a significant amount of time before being updated which makes the user experience sluggish.
A return ends processing of the function. Anything after a return is not processed.