SCRIPT5009:'fetch' 未定义
SCRIPT5009: 'fetch' is undefined
遇到一些麻烦!对于我的请求,我正在使用 Fetch API!
提交表单在 IE 中不起作用,因为 "SCRIPT5009: 'fetch' is undefined"!
外观示例:
fetch("url",
{
method: "POST",
body: JSON.stringify(data),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}).then(function (response) {
return response.json().then(function (data)
同时在 Chrome 和 FF 中工作正常!我已经尝试在冲浪 Google 上寻找一些解决方案,但没有帮助!
我尝试在 npm 中安装 "isomorphic-fetch" 和 "es6-promise",并尝试将其导入我的 .js 文件,但也没有成功,控制台显示如下:"Uncaught SyntaxError: Unexpected token import"!顺便说一句,required() 函数也不能正常工作!所以我现在完全不知道该怎么做,如何使用这些 polyfill 之类的东西!
如果有人有想法,在此先感谢!
BR!
您可以改用 https://github.com/github/fetch。
CDN:https://cdnjs.com/libraries/fetch
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script>
如果你需要 Promise
polyfill,你可以使用 http://bluebirdjs.com/docs/install.html
<script src="//cdn.jsdelivr.net/bluebird/3.5.0/bluebird.min.js"></script>
在fetch
之前加载Bluebird
:
<script src="//cdn.jsdelivr.net/bluebird/3.5.0/bluebird.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script>
遇到一些麻烦!对于我的请求,我正在使用 Fetch API!
提交表单在 IE 中不起作用,因为 "SCRIPT5009: 'fetch' is undefined"!
外观示例:
fetch("url", { method: "POST", body: JSON.stringify(data), headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' } }).then(function (response) { return response.json().then(function (data)
同时在 Chrome 和 FF 中工作正常!我已经尝试在冲浪 Google 上寻找一些解决方案,但没有帮助!
我尝试在 npm 中安装 "isomorphic-fetch" 和 "es6-promise",并尝试将其导入我的 .js 文件,但也没有成功,控制台显示如下:"Uncaught SyntaxError: Unexpected token import"!顺便说一句,required() 函数也不能正常工作!所以我现在完全不知道该怎么做,如何使用这些 polyfill 之类的东西!
如果有人有想法,在此先感谢! BR!
您可以改用 https://github.com/github/fetch。
CDN:https://cdnjs.com/libraries/fetch
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script>
如果你需要 Promise
polyfill,你可以使用 http://bluebirdjs.com/docs/install.html
<script src="//cdn.jsdelivr.net/bluebird/3.5.0/bluebird.min.js"></script>
在fetch
之前加载Bluebird
:
<script src="//cdn.jsdelivr.net/bluebird/3.5.0/bluebird.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script>