Loading an XML file with todays date in the filename... need to fallback to old file if one with tod
- by arala22
So here is my question. Using javascript/jQuery I am currently loading in an XML file that has a file name such as carousel_large_2010-06-08.xml.. the way I am doing it is checked for todays date then grabbing a file that has that date in the filename... the issue is sometimes they wont be uploading a new file for a given day so it needs to fallback to a older date that exists.. Wondering how to do it? Here is my code:
// set date for xml file
var currentTime = new Date(),
month = currentTime.getMonth() + 1,
day = currentTime.getDate(),
year = currentTime.getFullYear();
if(month.toString().length == 1){
month = '0'+month.toString();
}
if(day.toString().length == 1){
day = '0'+day.toString();
}
var dateObject = year+"-"+month+"-"+day;
// start magic
$jq.ajax({
type: "GET",
url: "_xml/carousel/home/carousel_large_"+dateObject+".xml",
dataType: "xml",
success: HPCarousels.heroCarousel.parseXML,
error: function(){
alert('Error Loading XML Content');
}
});