Solved

call a coldfusion function using jquery

Posted on 2010-08-27
1
609 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

705 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