Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
606 views
in Technique[技术] by (71.8m points)

javascript - SCRIPT5009: 'fetch' is undefined

have some troubles! For my requests i'm using Fetch API!

Submit form don't work in IE, because of "SCRIPT5009: 'fetch' is undefined"!

Example how it's looks like:

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)

Same time in Chrome and FF it's works fine! I'm already trying to find some solutions surfing Google, but it was unhelpful!

I was tried to installing "isomorphic-fetch" and "es6-promise" in npm, and tried to import it in my .js file, but it was unsuccessful as well, console shows me this: "Uncaught SyntaxError: Unexpected token import"! Btw, required() function don't work as well! So I'm totally don't now what to do, how to use these polyfill thing and all of that!

If some ones have an idea, thanks in advance! BR!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use https://github.com/github/fetch instead.

CDN: https://cdnjs.com/libraries/fetch

<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script>

If you need Promise polyfill you can use http://bluebirdjs.com/docs/install.html

<script src="//cdn.jsdelivr.net/bluebird/3.5.0/bluebird.min.js"></script>

Load Bluebird before fetch:

<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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...