diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2023-02-01 13:48:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-01 13:48:35 +0100 |
commit | a7ed9a7b6364273b1b964fd2cf9691dec2cbec6b (patch) | |
tree | 7503c5b33e00f93084d03617998f44149de35229 /test/unit/ajax.js | |
parent | 0b9c5037f707a0b8e0dbb11776b690ae7dde7123 (diff) | |
download | jquery-a7ed9a7b6364273b1b964fd2cf9691dec2cbec6b.tar.gz jquery-a7ed9a7b6364273b1b964fd2cf9691dec2cbec6b.zip |
Ajax: Support binary data (including FormData)
Two changes have been applied:
* prefilters are now applied before data is converted to a string;
this allows prefilters to disable such a conversion
* a prefilter for binary data is added; it disables data conversion
for non-string non-plain-object `data`; for `FormData` bodies, it
removes manually-set `Content-Type` header - this is required
as browsers need to append their own boundary to the header
Ref gh-4150
Closes gh-5197
Diffstat (limited to 'test/unit/ajax.js')
-rw-r--r-- | test/unit/ajax.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js index fec1d9565..7ecedc212 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -3105,4 +3105,47 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re assert.ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active ); } ); + ajaxTest( "jQuery.ajax() - FormData", 1, function( assert ) { + var formData = new FormData(); + formData.append( "key1", "value1" ); + formData.append( "key2", "value2" ); + + return { + url: url( "mock.php?action=formData" ), + method: "post", + data: formData, + success: function( data ) { + assert.strictEqual( data, "key1 -> value1, key2 -> value2", + "FormData sent correctly" ); + } + }; + } ); + + ajaxTest( "jQuery.ajax() - URLSearchParams", 1, function( assert ) { + var urlSearchParams = new URLSearchParams(); + urlSearchParams.append( "name", "peter" ); + + return { + url: url( "mock.php?action=name" ), + method: "post", + data: urlSearchParams, + success: function( data ) { + assert.strictEqual( data, "pan", "URLSearchParams sent correctly" ); + } + }; + }, QUnit.testUnlessIE ); + + ajaxTest( "jQuery.ajax() - Blob", 1, function( assert ) { + var blob = new Blob( [ "name=peter" ], { type: "text/plain" } ); + + return { + url: url( "mock.php?action=name" ), + method: "post", + data: blob, + success: function( data ) { + assert.strictEqual( data, "pan", "Blob sent correctly" ); + } + }; + } ); + } )(); |