FormData

HTML5 `FormData` polyfill for Browsers.

Github星跟踪图

FormData

Greenkeeper badge

Build Status

npm version

JavaScript Style Guide

npm install formdata-polyfill

A FormData polyfill

This polyfill conditionally replaces the native implementation rather then fixing the missing functions,
since otherwise there is no way to get or delete existing values in the FormData object.
Therefore this also patches XMLHttpRequest.prototype.send and fetch to send the FormData as a blob,
and navigator.sendBeacon to send native FormData.

I was unable to patch the Response/Request constructor
so if you are constructing them with FormData you need to call fd._blob() manually.

new Request(url, {
  method: 'post',
  body: fd._blob ? fd._blob() : fd
})

Dependencies

If you need to support IE <= 9 then I recommend you to include eligrey's blob.js

Previously you had to import the polyfill and use that,
since it didn't replace the global (existing) FormData implementation.
But now it transparently calls _blob() for you when you are sending something with fetch or XHR,
by way of monkey-patching the XMLHttpRequest.prototype.send and fetch functions.

So you maybe had something like this:

var FormData = require('formdata-polyfill')
var fd = new FormData(form)
xhr.send(fd._blob())

There is no longer anything exported from the module
(though you of course still need to import it to install the polyfill),
so you can now use the FormData object as normal:

require('formdata-polyfill')
var fd = new FormData(form)
xhr.send(fd)

Native Browser compatibility (as of 2020-01-13)

Based on this you can decide for yourself if you need this polyfill.

skarmavbild 2020-01-13 kl 20 16 36

This polyfill normalizes support for the FormData API:

  • append with filename
  • delete(), get(), getAll(), has(), set()
  • entries(), keys(), values(), and support for for...of
  • Available in web workers (just include the polyfill)

主要指标

概览
名称与所有者jimmywarting/FormData
主编程语言JavaScript
编程语言JavaScript (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2016-10-19 16:41:21
推送于2024-03-06 09:18:04
最后一次提交2022-10-12 15:55:34
发布数23
最新版本名称v4.0.10 (发布于 )
第一版名称2.0.3 (发布于 )
用户参与
星数358
关注者数8
派生数103
提交数185
已启用问题?
问题数92
打开的问题数2
拉请求数39
打开的拉请求数2
关闭的拉请求数11
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?