Reputation: 513
newbie to coldfusion/programming here and I would love some help! So right now the basic overview is that I was instructed to use AJAX to take information from a form and insert it into my database. I have a component constructed with a query inside a function:
<cfcomponent>
<cffunction name="set_all">
<cfargument name="Title">
<cfargument name="Description">
<cfargument name="Branch">
<cfargument name="DB">
<cfargument name="Club">
<cfargument name="Assignee">
<cfquery name="set_all_query" datasource="TicketFaster" username="TicketFasterLogin" password="TicketPassword">
INSERT INTO Tickets (Title, Description, Branch, Club_Database, Club, Assignee, Assigner)
VALUES ('#Title#', '#Description#', '#Branch#', '#DB#', '#Club#', '#Assignee#', '#session.username#');
</cfquery>
</cffunction>
And some jquery:
$(document).ready(function() {
$("#submit").click(function(f) {
var Title = $("input[name=Title]").val();
var Description = $("input[name=Description]").val();
var Branch = $("input[name=Branch").val();
var DB = $("input[name=DB]").val();
var Club = $("input[name=Club").val();
var Assignee = $("select[name=Assignee").val();
$.post("ticketcomponent.cfc", {Title, Description, Branch, DB, Club, Assignee});
});
});
So I'm taking in some inputted data (the variables) and then trying to call the set_all function from within the jquery function. Everything I've found online regarding jquery's post function simply writes their own function like here, but I want to invoke a function from the referenced cfc file. Is this possible? Or is the only option to hard code my query into the function argument?
Upvotes: 2
Views: 99
Reputation: 742
You can call the method with cfcname.cfc ?method=set_all
Shown here http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0ac4a-7fd9.html
The function has to have access="remote" so it's accessible to Ajax calls.
I didn't look at your jquery code but this is what you need to talk to the cfc.
Upvotes: 1