Corey Roth and Friends Blogs

Group site for developer blogs dealing with (usually) Ionic, .NET, SharePoint, Office 365, Mobile Development, and other Microsoft products, as well as some discussion of general programming related concepts.

Not Necessarily Dot Net

Real World Dojo part Three: AJAX

When we finished up last time, we had an AJAX-ified form that uploads an image file.

The problem now is that the "metadata" (the name and URL) are being completely ignored.  It's ugly, but try adding them as GET variables to the upload path:

It seems like I should just be able to update the uploadUrl right before calling doUpload():

                var name = dojo.byId("Name").value;
                var url = dojo.byId("Url").value;
                uploader.uploadUrl += "?name=" + escape(name);
                uploader.uploadUrl += "&url=" + escape(url);

but that doesn't work.  The SWF is given its upload URL when it's created.  The File Uploader object doesn't really have all that much interaction with it after that.

Oh, well.  It's not like that would be a valid long-term fix anyway (the real page that this is a proof-of-concept for has too many variables to put into the GET part of the URL).

So it's time to do the "AJAX thing."  After all, Dojo started out life as an AJAX library, right?  (Actually, I'm not at all sure of that.  They very well might have been planning a full-featured javascript library from Day One.  After all, the AJAX stuff is really just a tiny portion of what Dojo does).

It's not like there's much to this:

            var metaDataSubmit = function(){
                    url: "/beta/test/assign_metadata",
                    form: "TheTest",
                    handleAs: "text",
                    handle: function(data, args){
                        if(typeof data == "error"){

and add a call to that around the time you call uploader.upload();

url is where the postback goes to.  form is the ID of the form that holds the values of interest.  handleAs is where things get interesting.  Change it to "json" and you can actually return javascript objects.  handle is the function that gets called after the postback gets a response.

Of course, this implementation's complete nonsense.  In the real world, you need to assign some sort of ID (and some sort of security validation) to the requests so you can coordinate them.  Otherwise, how would you know which file went with which metadata?

Since that's really server-side stuff, I'll ignore actually generating that for now.

I feel odd writing such a short post, but that's really all there is to this.


No Comments

Leave a Comment

Powered by Community Server (Non-Commercial Edition), by Telligent Systems