In a $.each function I am calling jquery ajax method which is returning a list, so that returned list I want to use in other function and parallel that jquery ajax loop will also work and return the value continuously and call that other function, but it's not happening parallel,means after completing of $.each function it's calling the other function with the last returned list. But I want once its returned list call the other function with that returned value and like this continue.
function Test() {
var x = $('#myHiddenVar').val();
$.each($.parseJSON(x), function (key, value) {
$.ajax({
type: 'POST',
url: '@Url.Action("GeoIPDashboardDataload", "Home")',
data: { branchId: value },
async: false,
error: function (xhr, status, error) {
console.log(error);
},
success: function (data) {
debugger;
if (data != null) {
$(data.logs).each(function (index) {
debugger;
var _id = index;
var _logId = data.logs[index].id;
var _dstIP = data.logs[index].dst_ip;
var _dstCountryName = data.logs[index].dst_geoData.country_name;
var _dstlatitude = data.logs[index].dst_geoData.latitude;
var _dstlongitude = data.logs[index].dst_geoData.longitude;
var _srcIP = data.logs[index].src_ip;
var _srcCountryName = data.logs[index].src_geoData.country_name;
var _srclatitude = data.logs[index].src_geoData.latitude;
var _srclongitude = data.logs[index].src_geoData.longitude;
var _threatType = data.logs[index].threat_type;
var locations = {
"id": _id,
"logId": _logId,
"dstIP": _dstIP,
"dstCountryName": _dstCountryName,
"dstlatitude": _dstlatitude,
"dstlongitude": _dstlongitude,
"srcIP": _srcIP,
"srcCountryName": _srcCountryName,
"srclatitude": _srclatitude,
"srclongitude": _srclongitude,
"threatType":_threatType
};
queryStr = { "locations": locations };
queryArr.push(queryStr);
});
companyName = data.comp;
branchName = data.branch;
attacks.init();
}
}
});
});
}
------------
attacks = {
interval: getRandomInt(attack_min, attack_max),
init: function () {
setTimeout(
jQuery.proxy(this.getData, this),
this.interval
);
},
getData: function () {
var srclat = arr[arrayCount].src_geoData.latitude;
var srclong = arr[arrayCount].src_geoData.longitude;
var dstlat = arr[arrayCount].dst_geoData.latitude;
var dstlong = arr[arrayCount].dst_geoData.longitude;
var sourceip = arr[arrayCount].src_ip;
var attackerIP = arr[arrayCount].dst_ip;
var srccountry = arr[arrayCount].src_geoData.country_name;
attackdiv_slatlong = arr[arrayCount].dst_geoData.country_name;
hits.push({
origin: { latitude: srclat, longitude: srclong },
destination: { latitude: dstlat, longitude: dstlong }
});
map.arc(hits, { strokeWidth: 2 });
boom.push({
radius: 7, latitude: dstlat, longitude: dstlong,
attk: attackerIP
});
map.bubbles(boom, {
popupTemplate: function (geo, data) {
return '<div class="hoverinfo">' + data.attk +'</div>';
}
});
arrayCount++;
this.interval = getRandomInt(attack_min, attack_max);
this.init();
},
};
So the above test method calling from document.ready function and after pushing all item into the queryArr array call attack.init and inside attack.int i am using that array list.