-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* | ||
* jquery.binarytransport.js | ||
* | ||
* @description. jQuery ajax transport for making binary data type requests. | ||
* @version 1.0 | ||
* @author Henry Algus <[email protected]> | ||
* | ||
*/ | ||
|
||
(function($, undefined) { | ||
"use strict"; | ||
|
||
// use this transport for "binary" data type | ||
$.ajaxTransport("+binary", function(options, originalOptions, jqXHR) { | ||
// check for conditions and support for blob / arraybuffer response type | ||
if (window.FormData && ((options.dataType && (options.dataType == 'binary')) || (options.data && ((window.ArrayBuffer && options.data instanceof ArrayBuffer) || (window.Blob && options.data instanceof Blob))))) { | ||
return { | ||
// create new XMLHttpRequest | ||
send: function(headers, callback) { | ||
// setup all variables | ||
var xhr = new XMLHttpRequest(), | ||
url = options.url, | ||
type = options.type, | ||
async = options.async !== false, | ||
// blob or arraybuffer. Default is blob | ||
dataType = options.responseType || "blob", | ||
data = options.data || null, | ||
username = options.username || null, | ||
password = options.password || null; | ||
|
||
xhr.addEventListener('load', function() { | ||
var data = {}; | ||
data[options.dataType] = xhr.response; | ||
// make callback and send data | ||
callback(xhr.status, xhr.statusText, data, xhr.getAllResponseHeaders()); | ||
}); | ||
xhr.addEventListener('error', function() { | ||
var data = {}; | ||
data[options.dataType] = xhr.response; | ||
// make callback and send data | ||
callback(xhr.status, xhr.statusText, data, xhr.getAllResponseHeaders()); | ||
}); | ||
|
||
xhr.open(type, url, async, username, password); | ||
|
||
// setup custom headers | ||
for (var i in headers) { | ||
xhr.setRequestHeader(i, headers[i]); | ||
} | ||
|
||
xhr.responseType = dataType; | ||
xhr.send(data); | ||
}, | ||
abort: function() {} | ||
}; | ||
} | ||
}); | ||
})(window.jQuery); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters