I' trying to make a multiple ajax call and get the data accordingly. I'm making a call using a for loop and it works to a extend but the problem is the result I get is not in order and every time I refresh the results order changes.
$(document).ready(function() {
getEventData();
});
function getEventData() {
var cars = ["recFJekME3X8XF55g", "recpzMtGIWOfMVnMz", "recSholMmG3Q6axgq", "recRB9Bct42cbcV7C", "recExwVPJ5bxfOKGV"];
var length = cars.length;
var i;
for (i = 0; i < length; i++) {
if (i in cars) {
var url = 'https://api.airtable.com/v0/yourappid/tablename/' + cars[i] + '';
$.ajax({
url: url,
headers: {
'Authorization': key
},
type: 'GET',
ContentType: "application/json; charset=utf-8",
crossDomain: true,
success: function(data) {
processData(data);
},
error: function(data, errorThrown) {
alert("not success!!");
}
});
}
}
}
function processData(data) {
var title = data.fields['Product Title'];
var artUrl = data.fields['Manufacturer Homepage Link'];
$('#someDiv').append('<a href="' + artUrl + '" target="_blank"> <div class="title">' + title + '</div>');
}
<div class="wrapper">
<div id="someDiv"></div>
</div>
result before refreshing
result after refreshing