Задать вопрос
@Holfamer

Как вернуть значение из функции, где есть промисы?

Код:
function getKmzFileAsText() {
			    var text = '';
                var xhr = new XMLHttpRequest(),
                    fileReader = new FileReader();

                xhr.open("GET", "kmz/1.kmz", true);
                // Set the responseType to blob
                xhr.responseType = "blob";

                xhr.addEventListener("load", function () {
                    if (xhr.status === 200) {
                        // Load blob as Data URL
                        fileReader.readAsDataURL(xhr.response);
                        JSZip.loadAsync(xhr.response).then(function (content) {
                            // if you return a promise in a "then", you will chain the two promises
                            return content.files["doc.kml"].async('text');
                        })
							.then(function (txt) {
                            alert(txt);
                            text = String(txt);
                        });
                    }
                }, false);
                // Send XHR
                xhr.send();
                console.log(text);
//                return text;
            }
  • Вопрос задан
  • 243 просмотра
Подписаться 3 Комментировать
Подписчики вопроса 3 К ответам на вопрос (3)