Fixing jQuery Form Plugin Upload Responses

Android Certificate Installer uses jQuery Form Plugin ajaxForm to handle uploading and transloading certificates. The upload/transload response then provides the hash of the certificate. When tested, however, the response was surrounded by junk tags.

  1. <head></head><body>fd2ba47ae440c9405a573d0d03287f316dfe9eba</body>

Taking a look at the Form Plugin API, we see the plugin uses a hidden iframe to handle file uploads. A simple patch then adds the proper behavior. This patch is against version 2.49 of the un-minified plugin file.

  1. --- jquery.form.js 2010-11-06 14:16:53.792709557 -0400
  2. +++ /home/nicole/Projects/Sites/cooltrainer.org/js/jquery.form.js 2010-11-06 21:01:04.587884585 -0400
  3. @@ -349,7 +349,7 @@
  4. //log('response detected');
  5. cbInvoked = true;
  6. - xhr.responseText = doc.documentElement ? doc.documentElement.innerHTML : null;
  7. + xhr.responseText = doc.body ? doc.body.innerHTML : doc.docElement ? doc.docElement.innerHTML : null;
  8. xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
  9. xhr.getResponseHeader = function(header){
  10. var headers = {'content-type': s.dataType};

The data is now returned un-altered.

  1. fd2ba47ae440c9405a573d0d03287f316dfe9eba