FETCH IE11:第二次抓取在ie 11中不起作用

问题描述 投票:0回答:1

第一次调用fetch时,一切正常。在第二次通话中,我得到了错误。它可以在Chrome中正常运行。已连接Polyfill提取。

下面的代码在将其上传到服务器之前会转换为ES5。我已经隐藏了一些变量。

const url = `Fake url for example`;
function addData(data) {
            console.log("Affiche", data);
            const randomAffiche = data.data[getRandomInt(data.data)];
            const date = randomAffiche.PROPERTY_DATES_VALUE.split('-')[1];
            eventImgElem.src = randomAffiche.IMG;
            eventTitleElem.innerHTML = randomAffiche.NAME;
            eventTitleElem.href = randomAffiche.DETAIL_PAGE_URL;
            eventLink.href = randomAffiche.DETAIL_PAGE_URL;
            eventDate.innerHTML = getMonth(date);
            eventLink.innerHTML = randomAffiche.PROPERTY_VENUE_VALUE;
            whereToGoLink.href = '/kudago/';
        }

        function fetchData(city) {
            try {
                fetch(url + city) // This fetch is returned data = false. Why?
                    .then(data => {
                        data.json()
                            .then(data => {
                                console.log("fetchData", data);
                                addData(data);
                            })
                    })
            } catch (e) {
                console.log(e);
            }

        }

        function getCity() {
            const url = "fake url for example";
            try {
                fetch(url) // This fetch is good
                    .then(data => {
                        data.json()
                            .then(data => {
                                console.log("getCity", data)
                                if (data.data) {
                                    fetchData(data.data.name); 
                                } else {
                                    console.log("Error getCity", data);
                                }
                            })

                    })

            } catch (e) {
                console.log(e);
            }
        }
        getCity();
enter image description hereenter image description here

Chrome is ok

javascript internet-explorer fetch-api polyfills
1个回答
0
投票

此方法帮助了我https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

encodeURIComponent(url)

IE 11不懂西里尔字母。这将有助于那些要求西里尔字母的人。

© www.soinside.com 2019 - 2024. All rights reserved.