Solved

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

Posted on 2010-08-17
2
320 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
2 Comments
 
LVL 15

Accepted Solution

by:
Tomarse111 earned 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
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…

706 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

15 Experts available now in Live!

Get 1:1 Help Now