The code below does most of what I need. The function is run every time a new image is loaded onto the page. However this has created 100 server requests to the same xml file.. which is not good lets be honest.
So how do I rearange this function so only 1 xml request is used (even though im pulling 1 element out where i = id, the whole xml file is still cached) so i know i can use it.
function loadImages(i){
i++;
$.ajax
({
type: "GET",
url: "sites.xml",
dataType: "xml",
async: "true",
success: function(xml)
{
// these are the id's of images i do not want to load
var a = [2,3,4,5,6,7,8,9,19,18,60,61,50,49,79,78,81,82,80,70,90,91,92,93,94];
if ( a.indexOf( 2 ) !== -1 ) { // do this if not an 1 of the id's above
var img = $(xml).find('image[id=' + i + ']'),
id = img.attr('id'),
url = img.find('url').text();
$('#loading'+i).html('<img src="'+url+'" onLoad="loadImages('+i+')" />').hide();
$('#loading'+i).fadeIn();
}
}
});
}