var prev_item = -1; // No shopping item displayed yet. Random index will be set. function loadXMLShop(url){ var xhr; var dom_str,element1,element2,cat,item; if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari xhr=new XMLHttpRequest(); }else{// code for IE6, IE5 xhr=new ActiveXObject("Microsoft.XMLHTTP"); } xhr.onreadystatechange=function(){ if(xhr.readyState==4 && xhr.status==200){ var rand_i; element1=xhr.responseXML.documentElement.getElementsByTagName("shop"); if(prev_item == -1){ // This is the first time to show since the webpage has been loaded rand_i = Math.floor(Math.random() * (element1.length)); // set random between 0 ~ length of xml data. }else{ if(prev_item'; }catch(er){ dom_str=dom_str + ''; } } element2=element1[rand_i].getElementsByTagName("shop_name"); if(element2[0]){ try{ dom_str=dom_str + '
' + element2[0].firstChild.nodeValue + '
'; }catch(er){ dom_str=dom_str + ''; } } element2=element1[rand_i].getElementsByTagName("desc"); if(element2[0]){ try{ dom_str=dom_str + '
' + element2[0].firstChild.nodeValue + '
'; }catch(er){ dom_str=dom_str + ''; } } element2=element1[rand_i].getElementsByTagName("price"); if(element2[0]){ try{ dom_str=dom_str + '
' + element2[0].firstChild.nodeValue + '
'; }catch(er){ dom_str=dom_str + ''; } } function nextShop(){ $("#shop #shop_content").html(dom_str); } $("#shop #shop_content").effect('slide', { direction: "left", mode: "hide"},250,nextShop); $("#shop #shop_content").effect('slide', { direction: "right", mode: "show"},500); } } xhr.open("GET",url,true); xhr.send(); t=setTimeout("loadXMLShop('shop_data.php')", 4000); } $(document).ready(function(){ loadXMLShop('shop_data.php'); });