CFAjax

techscreencast.com
(Quality Technical Screencast)
Coldfusion Projects

CFAjax Installation

CFAjax comes with a sets of sample examples that you can install and experiment with, they provides you with the code sample on how the JavaScript library interacts with the coldfusion code.

Here is the step by step instruction on how to install CFAjax to run sample apps

  1. Extract the content of zip file to a particular folder. For same of simplicity we will extract it to the folder CFAjax
  2. Open the web server console and create a virtual folder by the name Ajax and point it to the folder where you extracted the zip file (i.e. the CFAjax folder)
  3. majority of installation will end at this point to check if CFAjax is installed properly browse the newly created virtual folder using the browser. (i.e. if this was installed on your local computer you can browser using this url http://localhost/ajax )

NOTE: in some cases the system/OS might not be able to resolved the localhost and instead of that you might have to use the machinename or 127.0.0.1 IP address if that is the case with your system, you should use the installation utility provide in the zip file i.e. browse to http://127.0.0.1/utility/installation.cfm following parameters should be provided to this utility

  • CFAjax Physical Path : Leave it to the default value
  • If IP Address has to be used
    New Virtual Path : http://127.0.0.1/ajax
  • If machine name has to be used (make sure you replace the machinename with the actual machine name of your computer)
    New Virtual Path : http://machinename/ajax
  • Press convert and follow through the rest of steps.
IMPORTANT : This utility should only be executed on CFAjax supplied examples, dont run it on your production website/app.


Using CFAjax on Existing/Production Site

In order to use CFAjax all you need is the core folder that comes along with the installation utility core folder has four files that are explained below.

  • engine.js : this is the main JavaScript file that sends and receives the data to the coldfusion server
  • utility.js : this JavaScript file provides with the utility function to be used in the client page (i.e the html page)
  • settings.js : this JavaScript file contains the location/reference of coldfusion page that has to be executed based on users action
  • cfajax.cfm : this is the core coldfusion page that marshals the request between the JavaScript page and the actual coldfusion pages.

In order to make Ajax calls from your html pages you have to include the following two .js files depending upon the location of where you copied the core folder you might have to change the src location

	<script type='text/javascript' src='/ajax/core/engine.js'></script>
	<script type='text/javascript' src='/ajax/core/util.js'></script>
	<script type='text/javascript' src='/ajax/core/settings.js'></script>

You will also have to specify the location of where the coldfusion function that you are calling are located

	<script language="javascript">
		_cfScriptLocation = "http://localhost/ajax/examples/functions.cfm";
	</script>
you can have a single coldfusion file that holds all your function or can have multiple files, choice is yours, but each of the coldfusion code files that you expose to CFAjax should include the parsing engine file "cfajax.cfm"
	<cfinclude template="core/cfajax.cfm">