Skip to content

Commit

Permalink
Merge pull request madrobby#1105 from askmatey/ajax-binary-data
Browse files Browse the repository at this point in the history
Ajax: Add support for receiving binary data (bug)
  • Loading branch information
mislav committed Dec 8, 2015
2 parents bfaf4bb + 040e38f commit 7b3c1b7
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,23 @@
var result, error = false
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) {
dataType = dataType || mimeToDataType(settings.mimeType || xhr.getResponseHeader('content-type'))
result = xhr.responseText

try {
// http://perfectionkills.com/global-eval-what-are-the-options/
if (dataType == 'script') (1,eval)(result)
else if (dataType == 'xml') result = xhr.responseXML
else if (dataType == 'json') result = blankRE.test(result) ? null : $.parseJSON(result)
} catch (e) { error = e }

if (error) ajaxError(error, 'parsererror', xhr, settings, deferred)
else ajaxSuccess(result, xhr, settings, deferred)

if (xhr.responseType == 'arraybuffer' || xhr.responseType == 'blob')
result = xhr.response
else {
result = xhr.responseText

try {
// http://perfectionkills.com/global-eval-what-are-the-options/
if (dataType == 'script') (1,eval)(result)
else if (dataType == 'xml') result = xhr.responseXML
else if (dataType == 'json') result = blankRE.test(result) ? null : $.parseJSON(result)
} catch (e) { error = e }

if (error) return ajaxError(error, 'parsererror', xhr, settings, deferred)
}

ajaxSuccess(result, xhr, settings, deferred)
} else {
ajaxError(xhr.statusText || null, xhr.status ? 'error' : 'abort', xhr, settings, deferred)
}
Expand Down

0 comments on commit 7b3c1b7

Please sign in to comment.