diff options
author | Richard Wall <richard@largo> | 2011-06-19 22:18:38 +0100 |
---|---|---|
committer | Richard Wall <richard@largo> | 2011-06-19 22:18:38 +0100 |
commit | 30a5e9abe7a477f14963a9188700c506623dd855 (patch) | |
tree | 99b2573894b5f4542b1f79b691ec5e3632dc1505 /jarmon | |
parent | 61d1dff1dd1125578c367f4419bc9545fcb65dc8 (diff) |
Fix things up for ie and use new ajax options
Diffstat (limited to 'jarmon')
-rw-r--r-- | jarmon/jarmon.js | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js index c318aee..6dde29b 100644 --- a/jarmon/jarmon.js +++ b/jarmon/jarmon.js @@ -38,36 +38,30 @@ jarmon.downloadBinary = function(url) { */ var d = new MochiKit.Async.Deferred(); - $.ajax({ - _deferredResult: d, url: url, dataType: 'text', - cache: false, - beforeSend: function(request) { - try { - request.overrideMimeType('text/plain; charset=x-user-defined'); - } catch(e) { - // IE doesn't support overrideMimeType - } + ifModified: true, + mimeType: 'text/plain; charset=x-user-defined', + xhr: function() { + // Save a reference to the native xhr object - we need it later + // in IE to access the binary data from responseBody + this._nativeXhr = jQuery.ajaxSettings.xhr(); + return this._nativeXhr; }, - success: function(data) { - try { - this._deferredResult.callback(new BinaryFile(data)); - } catch(e) { - this._deferredResult.errback(e); + dataFilter: function(data, dataType) { + // In IE we return the responseBody + if(typeof(this._nativeXhr.responseBody) != 'undefined') { + return new BinaryFile(this._nativeXhr.responseBody); + } else { + return new BinaryFile(data); } }, + success: function(data, textStatus, jqXHR) { + d.callback(data); + }, error: function(xhr, textStatus, errorThrown) { - // Special case for IE which handles binary data slightly - // differently. - if(textStatus == 'parsererror') { - if (typeof xhr.responseBody != 'undefined') { - this.success(xhr.responseBody); - } - } else { - this._deferredResult.errback(new Error(xhr.status)); - } + d.errback(new Error(xhr.status)); } }); return d; |