I'm new to ColdFusion but knowledgeable in JavaScript/jQuery. I've spent much time researching this question and think it must be simple, but couldn't come up with a solution.
I'd like to invoke a server-side call to a ColdFusion function from within my Javascript function. So that when the user clicks "Submit", and all requirements are met, an email is sent automatically through my ColdFusion mail server. No luck so far. This is what I have:
JavaScript:
function callback(value)
{
if (value)
{
if (newShowing) //checks validity of email address again before submitting
{
var email = $("#contactEmail").val();
}
else
{
var email = $("#contactEmail2").val();
}
var isEmail = validateEmail2(email);
if (isEmail == true)
{
//invoke coldfusion sendEmail function
$.get('/department/indexWebReq.cfm?method=sendEmail');
alert("Submitted Request!");
$("#webRequest-form").dialog("close");
}
}
}/
ColdFusion:
<cffunction name="sendEmail" returntype = "void">
<cfmail to="[email protected]"
from="[email protected]"
subject="Welcome to Bedrock"
type="text">
Dear User,
We, here at Bedrock, would like to thank you for joining.
Best wishes
Barney
</cfmail>
<cfoutput>
<p>Thank you, UserName, for registering.
We have just sent you an email.</p>
</cfoutput>
</cffunction>
access=remote. ie/path/to/YourComponent.cfc?method=someMethodName. That is what your original example was trying to do. The reason it did not work is because that syntax is only supported with .cfc's - not .cfm scripts.