From 30a5e9abe7a477f14963a9188700c506623dd855 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sun, 19 Jun 2011 22:18:38 +0100 Subject: Fix things up for ie and use new ajax options --- jarmon/jarmon.js | 40 +++++++++++++++++----------------------- 1 file 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; -- cgit v1.1-4-g5e80