owen

A project I’m currently messing with for WordPress has me delving more deeply into the XmlHttpRequest arena looking for something standard and well-maintained that I won’t have to tweak to incorporate. Matt suggested I try Dojo for this purpose. After speding a little more time looking it over, I was impressed enough with the workings of the library to attempt a test project (yet another WordPress plugin) using Dojo to do transparent server commuincations from the browser. This is that story.

Before I continue, note that I have been working completely on my own on this for less than 24 hours. These are initial unedited impressions of the whole toolkit, which I find (when I do finally get it working the way I want) should work marvelously for what I want to do. I haven’t bothered to contact the developers (yet) nor have I tried to read through all of the weightier (code-wise) mailing list archives. I don’t want to get on anyone’s bad side (particularly the Dojo devs) for saying bad things about anything, so I want to say explicitly that this is my story, as daft as I might have been following the path I did, and not a conclusion about how good/bad anything is. Your mileage will vary as a result of not following in the path of my own stupidity. Learn from my experience and avoid suffering.

My story begins yesterday afternoon. I had a downloaded copy of the initial Dojo release and was jumping up and down on it to fit it into my square hole. The plugin required that a form be submitted to the server without telling the user about it. It wasn’t a difficult task, and I didn’t care what the values sent to the server or returned from the server contained at the time. Everything worked fine, and I was encouraged by my success. Then I moved to a new computer and things started to unravel.

When I started to care what data was going to the server, that’s when my problems started. I must have spent four hours trying to figure out why the form was not being picked up by the server code. I think that my problem mainly stems from something odd in a WordPress $wpvarstoreset loop and my inference that the form’s method was going to be used by Dojo as the submission method.

Being unable to find Dojo documentation of any useful length (several of the bindArgs structure elements seem completely undocumented), I tried delving into the code. I learned a few things about the package.js that comes in the initial release.

First, it doesn’t seem very recent. Many additions have been made to the code since that initial release, including something vital to my success (more later). The latest release is available via SVN.

Second, the package.js file is a compressed version of a bunch of other files from the Dojo library. You don’t want to mess with the source in package.js, but the source that it’s built from. Don’t hurt yourself on the sharp edges of the release package.

I fought with WordPress for a bit. My form was submitting via GET no matter how I tried to get it to use POST. This was a problem because the data I was submitting could be quite long, and WordPress didn’t seem to like that my data was coming in via GET. Looking at the Dojo source (in its compressed form, mind you - not really understanding what the heck was going on there) I saw that XmlHttpRequest via POST was not available.

Fortunately, I found some information online that suggested that this functionality had been added in a SVN commit. So I looked around for the SVN repo, and finally found that. But the source wasn’t in the same format as what I had. Indeed, it seemed as though I would need to add many directories full of javascript source files to enable my plugin. This wasn’t good.

Some more searching yielded information associating Dojo to Apache ant. Ant is a built tool made in Java. It’s kind of like make. As I currently understand it, you use ant to turn all of those directories of source files into the single package.js file. Neat.

Well folks, I’m not a *nix binary coder. I have only rarely used non-Microsoft make tools, and only when I had complete instructions. So at about 1:30am, things were looking pretty bleak. I decided to get rest and then come back at it.

This morning, I’ve gathered all of the information for making this work on Windows. I’ve installed Python (which seems to be used in the builder) and Ant. I seemed to already have a JRE installed, so I didn’t actually need to download that. I used SVN to checkout the latest Dojo.

I added my Ant bin directory to the PATH. I added the environment variable ANT_PATH=C:\ant because the Ant docs said it was needed.

I opened a console window, changed to the Dojo checkout directory, and ran ant. There were errors, which the Dojo build script says is ok. I ran ant again, and got some options. Hmm…

I picked the obvious option, and ran ant release, which did produce output in the release directory. I looked at the package.js that was created, and was disappointed to see that there was still no POST method used anywhere in the source.

Remembering something I had read online during my many searches, I poked around the Dojo build directory into the profile section. I saw a profile there for what I wanted, browserio.profile.js. But how to enable that profile?

Here’s the command line you want:
ant -Dprofile=browserio -Ddocless=true release

And now the release package has source for POST via XmlHttpRequest. Whew. But does it work? Not quite.

The library seems to be built correctly, but it still needs some work to get it to do what I want. It is now using POST for all requests, regardless of what I try to tell it to use. I think this may be because I’m specifying a form to submit and the method of the form is POST (which is ironically what I originally wanted it to do). Now it’s ignoring the URL that I tell it to post the form to, which is very inconvenient. Maybe it was doing this before, but I didn’t notice since I was submitting the form to the same script that normally processes it. But in this new case, I want to send the form to a separate processor so I can return data appropriate for Dojo to use. It’s not doing this. I may need to tweak some parameters, which - as I said earlier - seem largely undocumented.

Ah, well. I’ll figure it out eventually. I was hoping everything was going to work fine by the end of writing this and I would be able to post the new plugin, but not so much. If I’m lucky, it’ll be later today. If not, who knows.

At least after playing with this, I’ll have a much better grasp of Dojo and how to apply it to the other thing I’m writing for WordPress, which will have to be less experimental on the first try.