Rob Gonda's Blog

ajaxCFC query retrieval example

Due to popular demand, I added an example that populates fields with information retrieved from a query. It actually has two versions of the code: one using client side JS and one using server side JS.
I created a query in ColdFusion so you do not depend on an external database to run this example. You should be able to easily replace the one I created with a real database.

As usual, I also added it to the download.

TrackBacks
There are no trackbacks for this entry.

Trackback URL for this entry:
http://www.robgonda.com/blog/trackback.cfm?932A831B-3048-7431-E4CD8FC82CFDB13F

Comments
Rob,
Thanks for this awesome example and clear explanation. I especially like the server side javascript/ AJAX.

Here are a couple links that your readers might be interested in to complement your posting:
http://jr-holmes.coldfusionjournal.com/calling_cf_...
http://www.indiankey.com/cfajax/examples.asp

Mark Holton
Coldfusion Developer
holtonma@gmail.com
http://holtsblog.blogspot.com/
# Posted By Mark Holton | 1/4/06 12:18 AM
Thanks Mark. I personally think that the documentation included with ajaxCFC is more complete than the links you provided, but that is my opinion.

Please note also that I am not using cfajax; as the matter of fact the main reason I built ajaxCFC is because of some lack of functionality of cfajax. Initially I contacted Arjun offering a bunch of upgrades I performed to his framework, and after no response for a few weeks, I decided to develop something better.

Anyways, those examples will not work with ajaxCFC. They are adaptable, but it is not the same methodology.

Please do not hesitate to critique my work, since that is the sole energy to build new and improved features.
# Posted By Rob Gonda | 1/4/06 12:40 AM
Haven't dug thu it yet, but what exactly do you mean by "server side JS"? You mean send the query along with js and eval clientside?

And the first example just sends data?

Thanks.

Btw, how does dwr play with prototype and scriptaculous, and what advantages did you see with dwr over prototype?
# Posted By stylo | 1/4/06 1:31 AM
Stylo, I'm sorry I left details out, I was following up in previews posts where I commented about only loading the JavaScript communication layer in the initial page and write all the JavaScript to be executed as the server level.

In the first example returned the dataset and the call handler parsed the data and assigned to the fields. In the second example, the server already writes the JavaScript and sends back the full command, which the handler function blindly executes. With this approach, 1) There's only need for one callback handler function, 2) You can secure more your JS, 3) Only load it when needed.

I am working on an example where you dynamically load functions into a namespace, allowing you to, for example, load the prototype, scriptaculos, or any other JS on-demand, and leave it in a local namespace after loading for future requests.

Now, scriptaculos does not work with DWR, as you probably know, it needs prototype; or maybe prototype-lite, not sure if it will work. You would have to load all of them, just like you would to use Rico, or load Dojo if you wanted to use that. This would be a good example where you could load them on-demand, and use a nice AJAX preloader after the core framework had been loaded.

Comparing prototype with DWR is more complicated; just like comparing them to Atlas… There're both have advantages and disadvantages, and honestly, I have not benchmarked them. If I have the time I could make an ajaxCFC version for prototype, but I don't see that coming anytime soon.
# Posted By Rob Gonda | 1/4/06 8:09 PM
Thanks.

I was more so wondering about your general impression of prototype vs. dwr for ajax, i.e., what's missing in each, easy in each, and such. I do realize prototype has more general hooks in it for development such as event handlers and such. Thing is I use a highly optimized library now for that, so was leaning more towards prototype as a replacement with it's ajax/json on top. Then again, I use cf, so...
# Posted By stylo | 1/5/06 10:21 AM
That is a great question ... I've been wondering the same, but never had time to due to proper research. Please keep me posted if you find anything interesting.

Thanks,

-Rob
# Posted By Rob Gonda | 1/5/06 10:47 AM
What is the best way to handle query data with special characters like '"() etc.? I would like to retrieve some larger varchar2 strings that contain these characters. Right now I experience a javascript [object error] when I try it.

thanks,
# Posted By NAME WITHHELD | 1/6/06 10:54 AM
What is the best way to handle query data with special characters like '"() etc.? I would like to retrieve some larger varchar2 strings that contain these characters. Right now I experience a javascript [object error] when I try it.

thanks,
# Posted By NAME WITHHELD | 1/6/06 11:07 AM
I'm just starting using the ajaxCFC framework. Looks very promissing. Only i have problems publishing query results to a page. So I got query results from a cfc function which i want to display in a table. I've used this code, but that doesn't work. can somebody help me with this?

function query_response(r){
   var getLabel = function(result) { return result.processLabel };
   var getLevel = function(result) { return result.processLevel };
   DWRUtil.removeAllRows("tableBody");
   DWRUtil.addRows("tableBody", r, [ getLabel , getLevel ]);
   }
# Posted By Mathijs Gaalman | 1/18/06 5:15 AM
Mathijs, I just posted a new entry regarding DWRUtil.addRows.
http://www.robgonda.com/blog/index.cfm/2006/1/18/a...
# Posted By Rob Gonda | 1/18/06 10:18 PM
I copied the "example query" to my shared remote server. While I am running this, I experience a javascript [objecterror]. I am looking into all the others comments, but I found no answer to this issue. can you tell me how this could be resolved. I read in of the commetns, there are issues when debugging is turned on. On my remote machine the debugging is turned off. But still I experience this problem.
# Posted By Sushma | 1/23/06 6:40 PM
This is awesome. I tried it and it works great. Thanks and keep more codes like this coming.
# Posted By Konsumativi | 9/20/06 4:29 AM
I am a little confused on one part. How do you modify it if you want to search by 2 text input forms?
# Posted By Chris | 10/9/06 4:36 PM
This blog is running version 5.9.003. Contact Blog Owner