Loading an XML file with todays date in the filename... need to fallback to old file if one with tod
Posted
by arala22
on Stack Overflow
See other posts from Stack Overflow
or by arala22
Published on 2010-06-08T16:49:07Z
Indexed on
2010/06/08
16:52 UTC
Read the original article
Hit count: 218
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');
}
});
© Stack Overflow or respective owner