[英]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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.