JSMX - Another AJAX API?

Today I was working on some AJAX code and realized that I would rather get my data from a CFC than from XML data. A few minutes of research later and I have JSMX up and running.

I already had a CFC with the method I needed to get my data with access="remote" (hopefully more on why I have this later - a new approach that seems promising). I thought it would be nice to add another remote method to generate the XML I needed for my AJAX.

This turned out to be rather easy, but I had to set returntype="void" and output="yes" and output the XML straight to the CFC page. This worked, but seemed a bit "hacky".

I was sure that someone had thought of a better way, so off to Google I went to find it.

JSMX advertises itself as an AJAX API - which it is (actually it advertises itself as "The Universal AJAX API"). It has some distinct advantages over other AJAX APIs that I have looked at (and never used). For one, it is just one 13K JS file. For another, it can easily digest data in a number of formats.

Notably, it can digest WDDX data. This is significant because that is the format of data you get if you do an HTTP "Get" on a remote method in a CFC.

The site has a few good examples of use , but none on WDDX. I was unable to find out how it structured the WDDX data in JavaScript. Fortunately, DP_Debug came to the rescue. This is basically cfdump for JavaScript - very handy.

I used the following syntax to test the results:

<script type="text/javascript">
http('GET', 'mycomp.cfc?method=mymethod', DP_Debug.dump);

This revealed that the results are basically identical to what you would get if you used <cfwddx> with action="CFML2JS". This made the JavaScript to digest the data even easier than it was to digest the XML.

My steps to implement JSMX:

  1. Copy the .js file to my site.
  2. Reference the .js file on my page.
  3. Change my JavaScript syntax appropriately (about a 5 minute job in my case) 

The result is that my JavaScript got smaller and easier to use and I was able to remove the file to serve up XML data and rely on the CFC to provide that data.

My only complaint about JSMX so far is that it could be much smaller than 13K if the comments and white-space were removed. Other than that small complaint, it is a thing of beauty!

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Maybe this one can be of help: http://dean.edwards.name/packer/

# Posted By Matthias | 2/8/07 3:13 PM
It would be an easy thing for me to remove the comments and extra white-space. The license forbids it.
# Posted By | 2/8/07 3:23 PM

I'd suggest trying out jQuery. It's only a few k larger than JSMX and it includes DOM manipulation methods, built-in animations and AJAX interaction, all in 19k. I use the same exact method you do to call the CFC (via an HTTP request).

Give it a look-see...www.jquery.com
# Posted By Andy Matthews | 2/9/07 1:27 AM

I am a little reluctant to add another 6K of download for functionality that I don't need.

On the other hand, I have seen plenty of people rave about jQuery. I guess I should check it out.

Maybe I will find that I need the extra functionality after all.

Thanks for the recommendation.
# Posted By | 2/9/07 11:56 PM
There is a compact version in the Google Groups for JSMX:

# Posted By Mike | 2/25/07 11:06 PM

Do you know if Todd has approved this version as being compatible with his license?

To quote from the header of the code:
# Posted By | 2/26/07 7:28 PM

I should probably use a better license (or remove all that version history from the header) ; ) You can compress the file if you would like. You are free to use the compressed version on the group site but I didn't compress it and therefore I only 'assume' it retains the full functionality of the "official" download.

You make some good points.
1. I need to do a better job of WDDX examples on the site.
2. I will start offering a compressed version as of my next rev.

# Posted By Todd Kingham | 3/16/07 3:35 PM

Great news! I will try to remember to download that version soon. No worries on the lack of docs on WDDX, it was easy to figure out.

Thanks for all of your work on JSMX. I really love it!
# Posted By Steve Bryant | 3/19/07 10:29 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.