简体   繁体   English

axios IE承诺不起作用

[英]axios IE promise doesn't work

I am using axios for ajax communication. 我正在使用axios进行ajax通信。 I have problem with IE. 我有IE的问题。 IE return error about Promise. 关于Promise的IE返回错误。 IE doesn't know anything about Promise. IE对Promise一无所知。

I am writing react/redux but I tried axios in plain JS and same result 我正在编写react / redux,但我在普通的JS中尝试了axios,结果相同

Could someone help me with it? 有人可以帮我吗? I am confused because axios should work on IE 8+ I tried on IE 11 (windows 10 64bit) 我很困惑,因为axios应该在IE 8上工作我试过IE 11(windows 10 64bit)

My trial is written as is in example on axios homepage 我的试用版是在axios主页上的示例中编写的

thx 谢谢

You have to include a promise polyfill if the browser has no promise implementation. 如果浏览器没有承诺实现,则必须包含promise polyfill。 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. axios docs提到它:axios依赖于支持的本机ES6 Promise实现。 If your environment doesn't support ES6 Promises, you can polyfill. 如果您的环境不支持ES6 Promises,您可以填充。

If you use just JS without transpiling or bundling you can try es6-promise 如果您只使用JS而不进行转换或捆绑,则可以尝试使用es6-promise

or if you use babel you can take its polyfill 或者如果你使用babel,你可以服用它的polyfill

Android 4.x and axios And Promise Android 4.x和axios和Promise

In Android 4.XI had similar problem. 在Android 4.XI中有类似的问题。 I solve it by using es6-promise in webpack config: 我通过在webpack配置中使用es6-promise来解决它:

Promise: 'es6-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 https://github.com/axios/axios/issues/188

Yes Promise wasn't introduced for Android until 4.4.4 是4.4.4之前没有为Android推出Promise

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


'Promise' is undefined '承诺'未定义

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM