jimmywarting / FormData

HTML5 `FormData` polyfill for Browsers and nodejs
MIT License
360 stars 102 forks source link

jquery & ajax #9

Closed jony89 closed 7 years ago

jony89 commented 7 years ago

before i used the plugin I've supplied directly the formData object created by new FormData() to $.ajax .

now i had to use _asNative() method:

            $.ajax({    
                url: ...,
                type: 'PUT',
                data: formData._asNative(),
                dataType: 'json',
                success: function(res) {
                    window.location.reload();
                },
                error: function() {
                    alert('..');  
                },
                processData: false,
                contentType: false,
                global: true
            });

I expect it to work the same.

jimmywarting commented 7 years ago

I don't extend FormData if such exist I have created a own class that XHR is unaware of what it's

polyfill is not an instance of window.FormData therefor it won't work The reason being that once i add stuff into the native partially supported FormData, I got no way to read, delete or edit the FormData... So i had to keep track of it myself

jimmywarting commented 7 years ago

And i don't want to monkey patch XHR, or Fetch to support it out of the box

if you want it to work out of the box then do something like this:

XMLHttpRequest = class extends XMLHttpRequest {
  send(data) {
    super.send(data instanceof polyfill ? data._blob() : data)
  }
}