Rob Gonda's Blog

ajaxCFC documentation added

I just updated the ajaxCFC download with initial documentation. I’ll keep improving as there is always room for improvement, but it has the minimal explanations and instructions to install and use.

If I’m missing something please do not hesitate to contact me, I will appreciate it.

ajaxCFC synchronous form validation

Now for the synchronous advantages, I created an example that shows one of the advantages for synchronous ajax. Upon form submission, a simple JavaScript code check for required fields and alerts a single message with the errors summary (try submitting a blank form).

If the email is provided, an ajax call makes sure the user doesn't already exist. Emails are stored in the session, if you try to create the same email more than once, the JavaScript alert will inform you that the email already exists. The advantage of the call being synchronous is that is can be incorporated with the rest of the form validation.

This process is doable with asynchronous ajax, but the only way to do it is for the form validation to always return false, and the call back function re-submit the form if appropriate. This process start becoming tedious if you need to validate several fields, such as address, email, captcha, username, and any other you may think of. The only way would be that each ajax call had to be initiated in the call-back from the previous call, in a cascade fashion… then also storing all the different results if you wanted to display a single error alert summary.

by the way, I added the multithreaded example and this one to the ajaxCFC download.

ajaxCFC multithreaded example

For all those who still have doubts about multithreaded ajax, I built an example that illustrates the differences between ordered and unordered batches, as well as synchronous and asynchronous.

Ordered batches will force the batch length to remain at (1) at all times, waiting for a response to come back before sending the next call.

Synchronous batches will halt the batch until the callback function has been resolved, making the entire process single threaded.

Note that the synchronous process will take a few seconds… this process in not meant to be used like this, but I wanted to illustrate the consequences. There are extremely handy uses of the synchronous process, which I'll show in a different example.

ajaxCFC error trapping

I just added a small but extremely useful tool to ajaxCFC: error trapping. When working with ajax applications something it’s hard to debug server side errors; of course, all the information travels asynchronously and if the server errors out, your call back function never gets triggered… well, you know there’s a problem, but what is it?

I had two methods of debugging:
1) check the server logs…
2) open an http header packet sniffer, check the method being calls, and emulate a direct call to get the output.

Therefore, I decided to add an error trapping to the server side and send the error back to the browser in an alert box. Now if you break anything in the server side you will immediately see the error message. Unfortunately, cfcatch doesn’t provide some useful information that cferror does, but it’s definitely extremely helpful.

If you have any more suggestions to make this framework as handy and useful as possible to the CF community, please do not hesitate to post a comment or email me directly.

ajaxCFC examples

I added two simple examples of ajaxCFC:

Echo example sends a string to the server, which just echoes it back to JavaScript and gets appended in a Div.

Complex object example uses the exact same code as echo, but this time it seamlessly receives a complex object from JavaScript and echoes it back. I used sDumper.js to dump the object into screen.

The component is extremely simple, all you have to do is extend ajax.cfc and you’re in business.
 

<cfcomponent extends="ajax">

    <cffunction name="echo" output="no" access="private">
        <cfargument name="args">
       
        <cfreturn args [1] />
    </cffunction>

</cfcomponent>

I tested this code with I.E 5.5, I.E 6, Netscape 7.2, FF 1.0+, FF 1.5, and Safari.

I will add more examples and add some documentation this weekend. I updated the zip file to include these examples as well.

Bye bye cfajax- hello ajaxCFC

After dealing with cfajax I decided to write my own AJAX component. Don’t get me wrong, I like cfajax and it worked great for a while. I even wrote two articles about CF+AJAX, but I wanted something better (article 1, article 2)

CFAJAX has some neat features like using hints to automate some processes, but unfortunately, they’re useless to me.

ajaxCFC is component based and extremely easy to expand. It also automatically and painlessly maps all JS strings, arrays, or objects to ColdFusion so there is no need for wddx or json.

ajaxCFC permits both asynchronous (default) or synchronous modes. Many may argue that it defeats the purpose, but I will post some examples soon that show how useful and necessary is to send synchronous packets.

You can download the framework and some examples through the projects page. Documentation will come soon.

As usual, comments are welcomed.

This blog is running version 5.9.003. Contact Blog Owner