there is an ajax request in the for loop that asks how to achieve the Synchronize effect without changing the parameter async of the ajax request to false.
where adding the async method to the code in es6 when compiling through gulp will make an error (the reason is unknown for the time being), so is there any other way to achieve the same effect?
var testAjax = async function () {
for(let i = 0; i < 5; iPP) {
console.log("test1: " + i);
var url = "xxx";
await $.ajax({
url: url,
dataType: "json",
type: "GET",
//async: false
}).then(function() {
console.log("test2: " + i);
}).fail(function() {
console.log("error")
});
}
}
testAjax();
request output
test1: 0
test2: 0
test1: 1
test2: 1
test1: 2
test2: 2
.
.
.