I need to get monthly statistics, and then the statistical cloud returns daily. So I passed the reference time for 12 months respectively. Call 12 times to get the total count for each month. Each time the resulting value is assigned to an array month. This array holds the total for 12 months. But because it"s an asynchronous request, I can"t get the variables inside the array outside. After I add async to ajax, the page loads very slowly.
var month = [];
getAppStatisticDataById(0,"2018-1-1","2018-1-31")
getAppStatisticDataById(1,"2018-2-1","2018-2-28")
getAppStatisticDataById(2,"2018-3-1","2018-3-31")
getAppStatisticDataById(3,"2018-4-1","2018-1-30")
getAppStatisticDataById(4,"2018-5-1","2018-1-31")
getAppStatisticDataById(5,"2018-6-1","2018-1-30")
getAppStatisticDataById(6,"2018-7-1","2018-1-31")
getAppStatisticDataById(7,"2018-8-1","2018-1-31")
getAppStatisticDataById(8,"2018-9-1","2018-1-30")
getAppStatisticDataById(9,"2018-10-1","2018-1-31")
getAppStatisticDataById(10,"2018-11-1","2018-1-30")
getAppStatisticDataById(11,"2018-12-1","2018-1-31")
function getAppStatisticDataById(index,start,end) {
$.ajax({
url: "https://r.apicloud.com/analytics/getAppStatisticDataById",
type: "post",
timeout: 10000, // 10
async :false,
headers: {
"X-APICloud-AppId": "xxxxxxxxx",
"X-APICloud-AppKey": varappKey,
},
dataType: "json",
data: {
startDate: start,
endDate: end
},
success: function(data) {
if(data.st == 1){
var count = 0;
for(let i = 0;i< data.msg.length; iPP){
//
count += data.msg[i].newRegsCount
}
//month
month[index] = count;
}
},
error: function(err) {
console.log(JSON.stringify(err)+"err")
},
complete: function(XMLHttpRequest, status) { //
// alert(JSON.stringify(XMLHttpRequest))
}
})
}