So this week had a painful technology ending… I’m preparing a site for a beta launch. My check list for Friday had an item on the list.: Test Ajax on the Mac (using Safari). We had been testing the Mac all through our dev cycle, but somehow I managed to not test the couple of places I’m using jaajax to enable AJAX callbacks. In the process I discovered a very important thing (and I hope I’m wrong). Sarissa.js doesn’t work with the Mac. Or rather if you are using Sarissa DOMParser for consistent XML XPathing, you will discover that Safari doesn’t work. I’m not sure if it’s version 2.0 of Safari (which is what my Mac uses… yes, I own one.. please forgive me, it’s only for testing scenarios like this one).
My first reaction was “Great… I hate Safari! Why can’t it come up to full standards… the marketing hype says it is… but why is it that the Mozilla-based browsers support a much wider array of programmable features!” Ok, you get the idea… I was living up to my boss’s monicker.
So what did I do… well, I want surfing to see if others had face the Safari/Ajax demon and killed it. Nope XmlHttp has been around since version 1.2 of Safari. And the Mac Marketing guys will note that “Hey you can actually use it for all the examples on Mozilla.com except of course the ones that use the DOMParser.” I really, really wanted to use XML under the covers.
I have a deadline and need to get this fixed, so I caved and came across a really cool little technology: JSON. It’s actually a really old technology that dates back to the standardizing of Javascript as ECMAScript. JSON is actually a shorthand notation for creating objects. So for instance my original jaajax source XML looked like this (sorry I don’t have the old source right in front of me)
<return>
<functionName_Return>return value as string</functionName_Return>
<functionName_Error>error string</functionName_Error>
</return>
I had to go through DOMParser gyrations to parse all this… Here’s the JSON version of the above:
{ “_Return”: “return value”, “_Error”: “Error string” }
You can parse this with a simple eval and it gives you an object with 2 properties: “_Return” and “_Error.” Did it work on the Mac? Yes, it did (although there were some other issues that I had to deal with in my original site).
Needless to say I am abandoning Sarissa and XML for future versions of my JAAJAX library (yep there is a future version coming soon! I haven’t abandoned it yet…I have big plans for the library going forward!)
[UPDATE: I guess I missed mentioning the major point here... COMPATIBILITY! This should be a fairly compatible way to transfer data and manipulate it via XMLHttp. Plus you get the added benefit of reconstituting a message (stealing from the SOAP guys) as a data object that is easily used within Javascripts]