I need to invoke a ColdFusion function(present in a .cfm file) when the user clicks on a link. And I would like to do it using jQuery. I have a jQuery snippet which looks like-
<script type="text/javascript">
$(document).ready(function(){
$("td.ViewLink a").click(function(event){
event.preventDefault();
)}
I am new to both jQuery and AJAX, so I might sound naive here. Should I use AJAX to invoke the ColdFusion function? Something like requesting to execute a specific function on the server.
Any help in this regard is appreciated.
Cheers.
If you have multiple functions in your cfm(even if you don't), put them in a cfc. Then you can use the following url pattern to invoke a specific method.
cfc named myEntityWS.cfc
<cfcomponent>
<cffunction name="updateDescription" access="remote" returntype="string">
<cfargument name="value" type="string" required="yes">
<cftry>
your code here
<cfcatch>
<cfoutput>
#cfcatch.Detail#<br />
#cfcatch.Message#<br />
#cfcatch.tagcontext[1].line#:#cfcatch.tagcontext[1].template#
</cfoutput>
</cfcatch>
</cftry>
</cffunction>
</cfcomponent>
Javascript
$.get('myEntityWS.cfc?method=updateDescription&value=someValue');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With