Link to home
Start Free TrialLog in
Avatar of brihol44
brihol44

asked on

Coldfusion Ajax function question

I'm using <cffunctions in regular .cfm pages (not .cfc). I've followed this code pattern from a couple of other developers and I know it's probably not standard practice but I find it convenient and easier to work with sometimes. So, in a ajax call is it still possible to call functions or methods with a .cfm extension file? I haven't been able to do so yet. My code below is what I've been working with.

$.ajax({
        type: "POST",
        url: "myfunctions.cfm?method=myfunctionname",
        data: "name=Tom",
        cache: false,
        success: function() {
          alert("yes");
        },
        error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(thrownError);
      }

    })

Open in new window


<cffunction name="deleteName"
			access="public"
			output="false"
			returntype="void"
			hint="delete name from users"
			>

<cfargument name="name"
				required="true"
				default=""
				type="string"
				hint="name">

	<cfquery datasource="#request.dsn#" username="#request.dsnUsername#" password="#request.dsnPassword#">
	DELETE
	FROM users
	WHERE name = '#arguments.name#'
	</cfquery>

</cffunction>

Open in new window

SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brihol44
brihol44

ASKER

lol... ok. I guess deserved that. So "No" then?
You can always open a page and if there's some code behind reading passed parameters run a function so the answer is yes, that just mean you're not calling expressively the function
ok, I tried that but I do have several functions on that page. It's not just the one cffunction I included in my example. I guess I didn't know how to run my example with it knowing what function to actually use.
All the function inside the page need to worry about if the << method >> parameter function is specified in the URL (query string) then DON'T run.
Doable but so bad, no?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
All good stuff and the feedback I was looking for. Thank you!