最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - FormData.entries() in Internet Explorer 11? - Stack Overflow

programmeradmin0浏览0评论

As found on the official documentation IE11 does not support FormData at all or at least not much enough I need to.

Inside my code I have to loop through the entries of an FormData element. For this task I use the entries() function which is not working on IE giving me the error

Object doesn't support property or method 'entries'

I already added via npm to my project and added it to my entry in webpack.config.js which then looked something like this.

const webpack = require("webpack");
const path = require("path");

module.exports = {
    entry: {
        app: ["babel-polyfill", "formdata-polyfill", "whatwg-fetch", "./Scripts/Modules/index.ts"]
    },
}

In the console I can see that formdata.min.js is loaded. As the error still occurs it seems like it does not use the polyfill as it should. It still uses the default one which fails. How can I tell my TypeScript code to use the polyfill-version instead of the browser's default implementation as the package does not provied any d.ts files?

Is this even possible? If not - what are possible workarounds for such a scenario?

This is what the FormData object is looking like in the dev-tools:

which only has append as method defined

As found on the official documentation IE11 does not support FormData at all or at least not much enough I need to.

Inside my code I have to loop through the entries of an FormData element. For this task I use the entries() function which is not working on IE giving me the error

Object doesn't support property or method 'entries'

I already added https://github./jimmywarting/FormData via npm to my project and added it to my entry in webpack.config.js which then looked something like this.

const webpack = require("webpack");
const path = require("path");

module.exports = {
    entry: {
        app: ["babel-polyfill", "formdata-polyfill", "whatwg-fetch", "./Scripts/Modules/index.ts"]
    },
}

In the console I can see that formdata.min.js is loaded. As the error still occurs it seems like it does not use the polyfill as it should. It still uses the default one which fails. How can I tell my TypeScript code to use the polyfill-version instead of the browser's default implementation as the package does not provied any d.ts files?

Is this even possible? If not - what are possible workarounds for such a scenario?

This is what the FormData object is looking like in the dev-tools:

which only has append as method defined

Share Improve this question edited Nov 19, 2017 at 23:53 KingKerosin asked Nov 19, 2017 at 23:35 KingKerosinKingKerosin 3,8515 gold badges44 silver badges86 bronze badges 4
  • perhaps you need the Object.entries polyfill? – Jaromanda X Commented Nov 19, 2017 at 23:40
  • @JaromandaX I've added a polyfill.js with the code from the link which is included before all other javascript-code but still get the same error. – KingKerosin Commented Nov 19, 2017 at 23:49
  • if you go to the console in the browser, is Object.entries defined? – Jaromanda X Commented Nov 19, 2017 at 23:50
  • Yes, seems like as it returns a function(obj). Will update my question with a screen of the error I'm facing. I don't event know where the error is exactly ing from as I am not that familiar with IE's developer tools – KingKerosin Commented Nov 19, 2017 at 23:51
Add a ment  | 

1 Answer 1

Reset to default 4

Not sure if it may helps you but I got this issue today and it seems that the version of the polyfill provided via NPM does not pletely override the FormData object, so is not suitable to IE11 or Edge.

I found switching to the V3 of the library fixed that. In order to do that I got the content of the FormData.js file from the github repository and added it as a ponent in my own custom JavaScript code.

I use WebPack to, got some other issues with IE11, still investigating.

Let me know how it goes by including the content directly instead of getting it from NPM.

发布评论

评论列表(0)

  1. 暂无评论