Wednesday, March 4, 2009

Using Ajax with coldfusion

http://livedocs.adobe.com/coldfusion/8/htmldocs/index.html

cfajaxproxy
Description
Creates a JavaScript proxy for a ColdFusion component, for use in an AJAX client. Alternatively, creates a proxy for a single CFC method, JavaScript function, or URL that is bound to one or more control attribute values.
Category
Internet protocol tags
Usage
Make sure that the Enable HTTP Status Codes option on the Server Settings > Settings page of the ColdFusion Administrator is selected. Otherwise, the proxy cannot determine if an error occurs in invoking the CFC function and cannot call the error handler.
A cfajaxproxy tag with a bind attribute does not refresh any control that is not specified in the bind expression.
If you specify a URL in the bind attribute, the HTTP response must consist of a single JSON representation of an object, array, or simple value, corresponding to the onSuccess argument.
Creating a CFC proxy
The cfajaxproxy tag with a cfc attribute generates a JavaScript proxy that represents a CFC on the web client. The tag and the proxy it generates have the following characteristics:
§ The proxy provides one function that corresponds to each CFC remote function. Calling these functions in your client-side JavaScript code remotely calls the CFC functions on the server.
§ The proxy provides several functions that you call to configure the interaction between the client and the server. These functions set the HTTP method and synchronization mode of the XMLHttpRequest call that the proxy uses to interact with the server. The functions also can specify a JavaScript callback handler and an error handler for asynchronous calls.
§ Because JavaScript is case-sensitive, you must ensure that you match the case of the keys in any ColdFusion structure or scope that you send to the client. By default, ColdFusion sets variable names and structure element names to all-uppercase. (You can create structure element names with lowercase characters by specifying the names in associative array notation, for example, myStruct["myElement"]="value".) The keys for the two arrays in the JSON object that the ColdFusion serializeJSON tag generates to represent a query are COLUMNS and DATA, for example, not columns and data.
For detailed information on using AJAX CFC proxies, see "Using ColdFusion Ajax CFC proxies" in "Using Ajax Data and Development Features" in the ColdFusion Developer's Guide.
Note: The proxy passes a _CF_NODEBUG Boolean argument to called CFC functions. ColdFusion checks this value, and when it is true, does not append to the response any debugging information that it normally would send. This behavior ensures that the JSON responses to AJAX requests do include any non-JSON (i.e., debug information) text

1 comment:

  1. Many websites involve using Ajax to avoid reloading the whole page which is very heavy and eats up time.Ajax allows reloading data on part of a page.I am a newbie to coldfusion although i am known to ajax but was not knowing how to use it with coldfusion thanks for sharing it.It saved me lots of time

    ReplyDelete