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);
DP_Debug.dump(MyObject)
</script>
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:
- Copy the .js file to my site.
- Reference the .js file on my page.
- 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!
Regards
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
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.
http://groups.google.com/group/JSMX/files
Do you know if Todd has approved this version as being compatible with his license?
To quote from the header of the code:
YOU ARE FREE TO USE THIS API IN ANY APPLICATION, TO COPY IT OR MODIFY THE FUNCTIONS FOR YOUR OWN NEEDS, AS LONG THIS HEADER INFORMATION REMAINS IN TACT
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.
Thanks,
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!