3 * jquery.binarytransport.js
5 * @description. jQuery ajax transport for making binary data type requests.
7 * @author Henry Algus <henryalgus@gmail.com>
11 // use this transport for "binary" data type
12 $.ajaxTransport("+binary", function(options, originalOptions, jqXHR){
13 // check for conditions and support for blob / arraybuffer response type
14 if (window.FormData && ((options.dataType && (options.dataType == 'binary')) || (options.data && ((window.ArrayBuffer && options.data instanceof ArrayBuffer) || (window.Blob && options.data instanceof Blob)))))
17 // create new XMLHttpRequest
18 send: function(headers, callback){
19 // setup all variables
20 var xhr = new XMLHttpRequest(),
23 async = options.async || true,
24 // blob or arraybuffer. Default is blob
25 dataType = options.responseType || "blob",
26 data = options.data || null,
27 username = options.username || null,
28 password = options.password || null;
30 xhr.addEventListener('load', function(){
32 data[options.dataType] = xhr.response;
33 // make callback and send data
34 callback(xhr.status, xhr.statusText, data, xhr.getAllResponseHeaders());
37 xhr.open(type, url, async, username, password);
39 // setup custom headers
40 for (var i in headers ) {
41 xhr.setRequestHeader(i, headers[i] );
44 xhr.responseType = dataType;