function ajax_async(url,format,callback){ var xhr = ajax_get_xhr(); if (xhr==null) return false; xhr.onreadystatechange = function(){ if (xhr.readyState==4){ if (format=='xml') callback(xhr.responseXML,xhr.status); else callback(xhr.responseText,xhr.status); } } xhr.open('GET',url,true); xhr.send(null); return true; } function ajax_sync(url,format){ var xhr = ajax_get_xhr(); if (xhr==null) return false; xhr.open('GET',url,false); xhr.send(null); return format=='xml'?xhr.responseXML:xhr.responseText; } function ajax_get_xhr(){ try{ xhr = new ActiveXObject('Msxml2.XMLHTTP'); }catch(e){ try{ xhr = new ActiveXObject('Microsoft.XMLHTTP'); }catch (e){ xhr = new XMLHttpRequest(); } } return xhr; } /* For product page */ function setWorthy(rid,rate){ var el = document.getElementById('worthy_text2'+rid); /*window['worthy_text2_'+rid] = el.innerHTML; // Store original text el.innerHTML = worthy_msg[2];*/ var func = function(result,status){worthyReady(rid,rate,result,status)}; ajax_async('ajax.php?ct=review_rate&rid='+rid+'&rate='+rate+'&f='+Math.random(),'text',func); } function worthyReady(rid,rate,result,status){ if (status==200){ w1 = parseInt(document.getElementById('worthy'+rid).innerHTML); w2 = parseInt(document.getElementById('unworthy'+rid).innerHTML); if (rate==1) w1++; else w2++; /*document.getElementById('worthy_score'+rid).innerHTML = w1; document.getElementById('worthy_text1'+rid).innerHTML = w1+'/'+(w1+w2)+worthy_msg[1]; document.getElementById('worthy_text2'+rid).innerHTML = worthy_msg[3];*/ if (result == 1){ document.getElementById('worthy_score'+rid).innerHTML = w1; document.getElementById('worthy'+rid).innerHTML = w1; document.getElementById('unworthy_score'+rid).innerHTML = w2; document.getElementById('unworthy'+rid).innerHTML = w2; if (rate == 1){ $('#yes'+rid).find('img').addClass('active'); $('#yes'+rid).find('img').attr('src','/images/icon/liked.png'); }else{ $('#no'+rid).find('img').addClass('active'); $('#no'+rid).find('img').attr('src','/images/icon/disliked.png'); } } }else{ document.getElementById('worthy_text2'+rid).innerHTML = '系統發生錯誤,未能提交您的評價,請稍候重試 (錯誤碼:'+status+')'; setTimeout('resetWorthyText('+rid+')',5000); } } function resetWorthyText(rid){ document.getElementById('worthy_text2'+rid).innerHTML = window['worthy_text2_'+rid]; }