jQuery(document).ready(function() {
groups = new Array();
jQuery('.showback').hide();
jQuery('.getPeople').on('click', function(event) {
event.preventDefault();
var data = jQuery('.parceForm').serialize();
jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: data,
success:function(data)
{
jQuery('.showback').show();
countMass = JSON.parse(data);
var progress = 100/countMass['key'];
var addProgress = 100/countMass['key'];
var k = 0;
for (var i = 0; i < countMass['key']; i++) {
jQuery.ajax({
url: membersurl,
type: 'POST',
data: {q:countMass[0][i]},
complete:function(data)
{
jQuery('.progress-bar').width(progress+"%");
progress += addProgress;
groups[k] = data;
k++;
}
});
};
},
complete:function(){
jQuery.ajax({
url: userurl,
type: 'POST',
data: {'tt': groups}
});
}
});
});
});
jQuery.ajax({
url: userurl,
type: 'POST',
data: {'tt': groups}
});
$(function () {
$('.showback').hide();
$(document).on('click', '.getPeople', function (e) {
e.preventDefault();
$.ajax({
url: ajaxurl,
type: 'POST',
data: $('.parceForm').serialize(),
dataType: 'json'
})
.done(function (countMass) {
$('.showback').show();
for (var i = j = 0, queue = [], groups = [], progress = 100 / countMass.key; i < countMass.key; i++) {
send(i);
}
function send (count) {
queue.push($.ajax({
url: membersurl,
type: 'POST',
data: {
q: countMass[0][count]
}
}).done(function (data) {
j++;
$('.progress-bar').width(progress * j + '%');
groups[count] = data;
}));
}
$.when.apply($, queue).then(function () {
$.ajax({
url: userurl,
type: 'POST',
data: {
tt: groups
}
});
});
});
});
});
jQuery(document).ready(function() {
groups = new Array();
jQuery('.showback').hide();
jQuery('.getPeople').on('click', function(event) {
event.preventDefault();
var data = jQuery('.parceForm').serialize();
jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: data,
success:function(data)
{
jQuery('.showback').show();
countMass = JSON.parse(data);
var progress = 100/countMass['key'];
var addProgress = 100/countMass['key'];
var k = 0;
var wtf = countMass['key'] - 1 // я ничего не сломал?
for (var i = 0; i <= wtf; i++) {
jQuery.ajax({
url: membersurl,
type: 'POST',
data: {q:countMass[0][i]},
complete:function(data)
{
jQuery('.progress-bar').width(progress+"%");
progress += addProgress;
groups[k] = data;
k++;
// ALL MAGIC HERE
if(i == wtf) { // сработает только после последнего запроса
jQuery.ajax({
url: userurl,
type: 'POST',
data: {'tt': groups}
});
}
}
});
};
}
});
});
});