code: function (url, data, timeout) {
  
     log.debug("new http_post request", url, data, timeout);
  
     var d = when.defer();
     var req = new XMLHttpRequest();
     req.withCredentials = true; // pass along cookies
     req.onreadystatechange = function () {
  
        if (req.readyState === 4) {
  
           // Normalize IE's response to HTTP 204 when Win error 1223.
           // http://stackoverflow.com/a/10047236/884770
           //
           var status = (req.status === 1223) ? 204 : req.status;
  
           if (status === 200) {
  
              // response with content
              //
              d.resolve(req.responseText);
  
           } if (status === 204) {
  
              // empty response
              //
              d.resolve();
  
           } else {
  
              // anything else is a fail
              //
              var statusText = null;
              try {
                 statusText = req.statusText;
              } catch (e) {
                 // IE8 fucks up on this
              }
              d.reject({code: status, text: statusText});
           }
        }
     }
  
     req.open("POST", url, true);
     req.setRequestHeader("Content-type", "application/json; charset=utf-8");
  
     if (timeout > 0) {
        req.timeout = timeout; // request timeout in ms
  
        req.ontimeout = function () {
           d.reject({code: 501, text: "request timeout"});
        }
     }
  
     if (data) {
        req.send(data);
     } else {
        req.send();
     }
  
     if (d.promise.then) {
        // whenjs has the actual user promise in an attribute
        return d.promise;
     } else {
        return d;
     }
  }
docs: Helper to do HTTP/POST requests returning deferreds. This function is supposed to work on IE8, IE9 and old Android WebKit browsers. We don't care if it works with other browsers.