Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

is it possible to pass data to an insert query in a cfc via javascript?

Posted on 2010-08-17
2
Medium Priority
?
329 Views
Last Modified: 2012-05-10
Hi, I have a cfc page containing an insert statement to a db and on my cfm page, I have various javascript functions, one in which is a save() function. In this function, I want to pass data from my form via javascript to the insert query in my cfc. Is this possible? If so, how are there any examples?

I will be attaching a code snippet shortly cause I am currently away from my pc where the code resides. In the meantime, if someone could give me any examples or references that would be appreciated. Thanks.
0
Comment
Question by:grnmachine
[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
2 Comments
 
LVL 15

Accepted Solution

by:
Tomarse111 earned 2000 total points
ID: 33456485
You can do this via an AJAX post to a remote function within your CFC.

Using a library such as jQuery will make this a 100 times easier. See below for some example code
/*AJAX call using Jquery*/

$.post("test.cfc?method=functionName", { name: "John", time: "2pm" },
   function(data){
     alert("Data Loaded: " + data);
   });

/*Code in your CFC*/
<cffunction name="functionName" access="remote" output="no">     
<cfquery datasource="yourDatasource">
    INSERT INTO yourTable
    (Name, Time) VALUES (<cfqueryparam value="#FORM.name#" cfsqltype="cf_sql_varchar">,<cfqueryparam value="#FORM.Time#" cfsqltype="cf_sql_varchar">)
</cfquery>
<cfreturn "Inserted correctly">
</cffunction>

Open in new window

0
 

Author Closing Comment

by:grnmachine
ID: 33456826
Thanks, this works well.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

597 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