Solved

call a coldfusion function using jquery

Posted on 2010-08-27
1
605 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Angular- another way of coding hide and display 3 48
Replace &lt; with < 14 59
javascript date picker in php while loop 5 48
How to position loader with CSS 3 36
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
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…

776 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