• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 613
  • Last Modified:

call a coldfusion function using jquery

I have a cfm file that has a url that directs the page to another cfm page
I would like on clicking the url to call a coldfusion function befor going to the next page
example
I have a component mycomponent
<cfcomponent>
<cffunction name="increaseviews">.
<cfargument arg1..>
...</cffunction></cfcomponent>

I have a cfm
mypage.cfm
<a href="mysecondpage.cfm">go to second page</a>

secondpage.cfm
I am the second page

I want the user on clicking on the url the jquery will call the function increaseviews then go to secondpage.cfm

Thanks in advance
0
sohairzaki2005
Asked:
sohairzaki2005
1 Solution
 
duncancummingCommented:
Firstly, in your cffunction add the attribute access="remote"

I assume your function doesn't return any information, but if it did, you'd probably want to add returnformat="json" in there too.

Secondly, in mypage.cfm, stick an ID attribute on your link, to make it easier to identify with the jQuery:

<a href="secondpage.cfm" id="yourlink"></a>

Thirdly, add some javascript like this into mypage.cfm:

$(document).ready(function() {
  $('#yourlink').click(function() {
     $.get("yourcfc.cfc?method=increaseviews", {arg1:'blah',arg2:foo});
  });
});
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now