I have this ajax function that loads a php script for each item in an array and then appends it to an html tag. The issue is that the scripts are appending out of order. How do I preserve the order of the objects?
jQuery(function($) {
$.getJSON('apiUrl.com', function(response) {
$.each(response.data, function(key, val) {
$.get("phpFile.php", {
id: val.id,
title: val.title,
img_url: val.images.jpg.image_url
}, function(html) {
$("#elementToLoadPhpFile").append(html);
});
});
});
});