Skip to main content
Inspiring
April 22, 2017
Question

Coldfusion code to handle Ajax request (posted variables)

  • April 22, 2017
  • 2 replies
  • 1029 views

I have used ColdFusion for database interaction (in standard form-submit based apps). Right now I need to attempt something fancier. The plan is to use JQuery to do an Ajax post of variables to a server, and I'm hoping to use ColdFusion to handle these Ajax requests.  I have no experience with Ajax, but I'm hoping to learn. Can someone please refer me to some examples so I can figure out how to do this? Sorry to be such a newbie on the topic. I appreciate any help.

    This topic has been closed for replies.

    2 replies

    Legend
    April 25, 2017

    Short answers: Yes. There are various ways to accomplish the task. I prefer not to use the CFC method as Carl referenced just because I like knowing and controlling every factor - I'm kind of OCD about stuff like this. The CFC method hides a lot of the lower level stuff but to me this makes it harder to diagnose if and when problems occur once your code has contact with the enemy, er, users.

    Again as Carl mentioned, security and authentication must be considered. I go even further, security should be the core and everything else would be considered "features". But then again, I mostly deal with payments so I tend to be a little paranoid.

    Carl Von Stetten
    Legend
    April 22, 2017

    I'd start with the jQuery docs for making AJAX requests.  While their examples likely reference PHP or other language for the server-side stuff, that can easily be done with ColdFusion instead.  You can use either a .cfm page to provide the response, but it's usually a little easier to do it via a component (.cfc) with a "remote" function (that way you can return only the JSON or XML data you want to and not any extraneous HTML "noise").  Here is some documentation on writing components, and there is a section about invoking methods (functions) from a URL or FORM (which is essentially what AJAX requests are doing).

    There can be a lot more to it - security and authentication issues need to be considered - but that should get you started.

    -Carl V.