Rob Gonda's Blog

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.

Google Sitemap for blogCFC 4.0

A few months ago Ray posted some code to generate a google sitemap.xml for blogCFC. He said it’s not final and it will be included in version 4… I guess there was no demand, or no one reminded him because it wasn’t included… In case anyone needs it, here’s a slightly altered version of the code to work for everyone.

<cfsetting enablecfoutputonly=true showdebugoutput=false>
<cfprocessingdirective pageencoding="utf-8">

<cfset params = structNew()>
<!--- Should be good for a while.... --->
<cfset params.maxEntries = 99999>
<cfset params.mode = "short">

<cfset entries = application.blog.getEntries(params)>

<cfset z = getTimeZoneInfo()>
<cfif not find("-", z.utcHourOffset)>
   <cfset utcPrefix = "-">
<cfelse>
   <cfset z.utcHourOffset = right(z.utcHourOffset, len(z.utcHourOffset) -1 )>
   <cfset utcPrefix = "+">
</cfif>

<cfset dateStr = dateFormat(entries.posted[1],"yyyy-mm-dd")>
<cfset dateStr = dateStr & "T" & timeFormat(entries.posted[1],"HH:mm:ss") & utcPrefix & numberFormat(z.utcHourOffset,"00") & ":00">

<cfcontent type="text/xml"><cfoutput><?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
   <url>
      <loc>#GetDirectoryFromPath(application.blog.getProperty("blogURL"))#</loc>
   <lastmod>#dateStr#</lastmod>
      <changefreq>hourly</changefreq>
      <priority>0.8</priority>
   </url>
   </cfoutput>
   <cfoutput query="entries">
      <cfset dateStr = dateFormat(posted,"yyyy-mm-dd")>
      <cfset dateStr = dateStr & "T" & timeFormat(posted,"HH:mm:ss") & utcPrefix & numberFormat(z.utcHourOffset,"00") & ":00">
      <url>
      <loc>#xmlFormat(application.blog.makeLink(id))#</loc>
      <lastmod>#dateStr#</lastmod>
      </url>
   </cfoutput>
<cfoutput>
</urlset>
</cfoutput>

Just create a file called sitemap.cfm in your blog root and paste the code above.

ISAPI Rewrite

Looking for extreme SEO, I decided to play with ISAPI Rewrite. It is nice and all using /index.cfm/var1/val1, but if you just could get rid of that index.cfm … I already built a /go/ module, so if that’s all you need, don’t buy the ISAPI Rewrite…

You can accomplish the /go/ redirect that Macromedia, among others use, by going to the specific site’s 404 Custom error and forward it to /404.cfm, which is a landing page you build with CF. The page will check it the URL has a /go/ syntax; if it does, it will cflocate to the appropriate destination, and if it doesn’t, it will cfcontent the original 404 error page. You can also use cfheader and change the status to 404, page not found.

The Rewrite module can accomplish much more than this, and it’s worth looking. In the process of playing and investigating the ISAPI Rewrite module for IIS, I found that Brandon Purcell recently blogged about it, and it’s extremely helpful. You can find more information here.

Ray also posted a short entry on SES after a filename.cfm. I also made the SES funcion I've been using for a while available here. It included SES parsing, and an SES construction function.

I’ll post more details in a few days.

JIC, I saved a copy of Bandon's blog here.

just updated to blogCFC 4.0

The blog is running now on BlogCFC 4.0.

Thanks Ray.

For more information please visit Ray's site.

Excellent medium/advanced Flash Forms tutorial

Excellent medium/advanced Flash Forms tutorial

http://www.macromedia.com/devnet/coldfusion/articles/flashforms.html

You can find a working version here:

http://www.asfusion.com/apps/realestate/

CFJD Article #2

I’m pleased to inform that the second part of my AJAX article was release yesterday. Check is out at

http://coldfusion.sys-con.com/read/154244.htm

Comments are welcomed.

Cheers

cf Quick Docs

 

This makes reference to the same quick docs from Macromedia, but it’s made with cfajax and it’s way faster

 
http://www.techfeed.net/cfQuickDocs/

More Entries

This blog is running version 5.9.003. Contact Blog Owner