我在尝试在Internet Explorer中进行异步工作时遇到问题。 它可以在其他浏览器上使用。
我尝试使用babeljs.io重新编译js
这是我要运行的方法,我使用babeljs.io将其编译为es2017
async function uploadStateLoop() {
var endingStatesArr = ["Not enough privileges for uploading","Upload successful", "Session ended", "Session ended - refresh your page"];
var stateID = getCookie('uploadStateID');
var req = new XMLHttpRequest();
do {
var response = req.responseText;
req.onreadystatechange = function () {
console.log(response);
if (req.readyState == XMLHttpRequest.DONE) {
$('#uploadState').text('Upload state: ' + response);
}
};
req.open('GET', '/uploadstate?id=' + stateID);
req.send();
await sleep(500);
} while (endingStatesArr.indexOf(response) < 0);
$('#blabla-upload').attr("disabled", false);
$('#blabla-upload').val(null);
$('#uploadProgressBar').fadeTo(5000, 0);
}
这是重新编译的输出:
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function() {
var self = this,
args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function uploadStateLoop() {
return _uploadStateLoop.apply(this, arguments);
}
function _uploadStateLoop() {
_uploadStateLoop = _asyncToGenerator(function*() {
var endingStatesArr = [
"Not enough privileges for uploading",
"Session ended",
"Session ended - refresh your page"
];
var stateID = getCookie("uploadStateID");
var req = new XMLHttpRequest();
do {
var response = req.responseText;
req.onreadystatechange = function() {
console.log(response);
if (req.readyState == XMLHttpRequest.DONE) {
$("#uploadState").text("Upload state: " + response);
}
};
req.open("GET", "/uploadstate?id=" + stateID);
req.send();
yield sleep(500);
} while (endingStatesArr.indexOf(response) < 0);
$("#blabla-upload").attr("disabled", false);
$("#blabla-upload").val(null);
$("#uploadProgressBar").fadeTo(5000, 0);
});
return _uploadStateLoop.apply(this, arguments);
}
所以,现在,我在这一行得到语法错误:
_uploadStateLoop = _asyncToGenerator(function*() {
我相信应该是“(”而不是*。 有任何想法如何使其正常工作吗?