aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/ajax.js
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2015-10-31 11:24:04 -0400
committerDave Methvin <dave.methvin@gmail.com>2015-11-04 12:47:16 -0500
commit769446c69775f6c44e35cee1bcdeccafba51be7b (patch)
treeede10c3a724f9460a41e4e85def8212cb768f073 /test/unit/ajax.js
parent76e9a95dbeaf28fbc5a64571ebb5959f91a9c14a (diff)
downloadjquery-769446c69775f6c44e35cee1bcdeccafba51be7b.tar.gz
jquery-769446c69775f6c44e35cee1bcdeccafba51be7b.zip
Ajax: Don't throw exceptions on binary data response
Fixes gh-2498 Closes gh-2682 The added unit test shows how this could be used to support an ArrayBuffer return, but $.ajax does not support it natively. The goal with this change was to avoid the exception.
Diffstat (limited to 'test/unit/ajax.js')
-rw-r--r--test/unit/ajax.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 4f0530656..12bf2ab31 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1660,6 +1660,30 @@ QUnit.module( "ajax", {
};
} );
+if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().responseType !== "string" ) {
+
+ QUnit.skip( "No ArrayBuffer support in XHR", jQuery.noop );
+} else {
+
+ // No built-in support for binary data, but it's easy to add via a prefilter
+ jQuery.ajaxPrefilter( "arraybuffer", function ( s ) {
+ s.xhrFields = { responseType: "arraybuffer" };
+ s.responseFields.arraybuffer = "response";
+ s.converters[ "binary arraybuffer" ] = true;
+ });
+
+ ajaxTest( "gh-2498 - jQuery.ajax() - binary data shouldn't throw an exception", 2, function( assert ) {
+ return {
+ url: url( "data/1x1.jpg" ),
+ dataType: "arraybuffer",
+ success: function( data, s, jqxhr ) {
+ assert.ok( data instanceof window.ArrayBuffer, "correct data type" );
+ assert.ok( jqxhr.response instanceof window.ArrayBuffer, "data in jQXHR" );
+ }
+ };
+ } );
+}
+
QUnit.asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function( assert ) {
// Support: Android 2.3 only