Solved

call a coldfusion function using jquery

Posted on 2010-08-27
1
603 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
ID: 33548831
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
custom jquery validation method 11 28
Problem with data displaying 2 22
ajax form sumbit 3 56
Angular - where do I need to put this code? 3 29
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
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…

911 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

23 Experts available now in Live!

Get 1:1 Help Now