Solved

call a coldfusion function using jquery

Posted on 2010-08-27
1
602 Views
Last Modified: 2012-06-27
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
Comment
Question by:sohairzaki2005
1 Comment
 
LVL 16

Accepted Solution

by:
duncancumming earned 250 total points
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now