Design Diary: Frickin’ Time-Consuming Ad-hoc Tests of My YUI-based Ajax
My YUI-based Ajax is biased toward XML over HTTP. So, of course, I needed my ‘ingenious invention’ for simple string posts—the old fashioned application/x-www-form-urlencoded
stuff. Ideally my solution should be able to handle both formats. Yesterday it was not:
- So, first,
Ajax.js
was modified to see astringGetter
function (as well as anxmlGetter
). - The Zend framework had to be checked to verify that the PHP
$_POST
array was being filled (hey, you never know). And then the contents of$this->getRequest()->getParams()
was checked for$_POST
data. After a slip up that mistook the roleid
attributes play in form elements (these are not likename
attributes), it all worked. (This is a common mistake that I make since I use my AJAX stack to submit form data—I forgot how to do send data the old-fashioned way). - Then YUI without my code on top of it had to be checked to verify that a raw
application/x-www-form-urlencoded
string can actually be read by PHP/Zend Framework. This worked. - Then my core helper function that calls
YUI.util.Connect.asyncRequest()
was checked to verify that it was calling YUI properly. This worked. - Finally, my convenience function at the top of this entire stack was called. Assembling all of the data to pass into this function was a chore. I blame myself for designing it this way… not very test friendly… In any case, this worked. But! But when I changed the explicit setting of
application/x-www-form-urlencoded
toapplication/xml
, PHP$_POST
came up empty again. The lessons learned here are old ones and new ones. The elder lesson is that trying new code in the political IT workplace is very risky. In a “perfect world,” I would rather test new code on “my own time”—literally leave the labor camp for about three months to work on my new shit and then come back when I think I am done.
The newer lesson for me is to consider using the ‘named parameters’ pattern in JavaScript: passing an object, using its properties as parameters instead of passing in a bunch of arguments that are time-consuming to track.
One consideration (not really a lesson) is to learn how to use YUI debugging/testing methodologies. A new consideration as well is recognizing the YAHOO.util.Connect.setForm()
method: “This method assembles the form label and value pairs and constructs an encoded string. asyncRequest()
will automatically initialize the transaction with a HTTP header Content-Type of application/x-www-form-urlencoded
.” This member has been around for at least a year.