axios IE promise doesn't work

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 05:05:48

问题


I am using axios for ajax communication. I have problem with IE. IE return error about Promise. IE doesn't know anything about Promise.

I am writing react/redux but I tried axios in plain JS and same result

Could someone help me with it? I am confused because axios should work on IE 8+ I tried on IE 11 (windows 10 64bit)

My trial is written as is in example on axios homepage

thx


回答1:


You have to include a promise polyfill if the browser has no promise implementation. This sounds complicated but there are really good libs.

The axios docs mention it: axios depends on a native ES6 Promise implementation to be supported. If your environment doesn't support ES6 Promises, you can polyfill.

If you use just JS without transpiling or bundling you can try es6-promise

or if you use babel you can take its polyfill




回答2:


Android 4.x and axios And Promise

In Android 4.X I had similar problem. I solve it by using es6-promise in webpack config:

Promise: 'es6-promise'

plugins: [
    //tells webpack where to store data about your bundles.
    new BundleTracker({filename: './webpack-stats.json'}),

    //makes jQuery available in every module
    new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
        Promise: 'es6-promise'
    }),

    // Configure path for served CSS files ("desktop_css" will be served as /dist/desktop_css.css)
    new ExtractTextPlugin('[name].css'),
],

For more Information look at:

https://github.com/axios/axios/issues/188

Yes Promise wasn't introduced for Android until 4.4.4

http://caniuse.com/#feat=promises


'Promise' is undefined

https://github.com/webpack/webpack/issues/4254



来源:https://stackoverflow.com/questions/35769777/axios-ie-promise-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!