skrypt przerobiłem żeby działał na cookie ale mam problem gdyż głosowanie poprzez javascript mi nie działa. wywołuję je poprzez wstawienie w odnośnik java script:sndReq('1','4'). jedyne co się dzieje to pojawia się animacja podczas której niby zapisywane są wyniki i potem powinny pokazać się już zaktualizowane wyniki jednak animacja jest cały czas
javascript do tego wygląda tak:
var xmlhttp /*@cc_on @*/ /*@if (@_jscript_version >= 5) try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP") } catch (e) { try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") } catch (E) { xmlhttp=false } } @else xmlhttp=false @end @*/ if (!xmlhttp && typeof XMLHttpRequest!='undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp=false } } function myXMLHttpRequest() { var xmlhttplocal; try { xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP") } catch (e) { try { xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP") } catch (E) { xmlhttplocal=false; } } if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') { try { var xmlhttplocal = new XMLHttpRequest(); } catch (e) { var xmlhttplocal=false; alert('couldn't create xmlhttp object'); } } return(xmlhttplocal); } function sndReq(vote,id_num) { var theUL = document.getElementById('unit_ul'+id_num); // the UL // switch UL with a loading div theUL.innerHTML = '<div class="loading"></div>'; xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num); xmlhttp.onreadystatechange = handleResponse; xmlhttp.send(null); } function handleResponse() { if(xmlhttp.readyState == 4){ if (xmlhttp.status == 200){ var response = xmlhttp.responseText; var update = new Array(); if(response.indexOf('|') != -1) { update = response.split('|'); changeText(update[0], update[1]); } } } } function changeText( div2show, text ) { // Detect Browser var IE = (document.all) ? 1 : 0; var DOM = 0; if (parseInt(navigator.appVersion) >=5) {DOM=1}; // Grab the content from the requested "div" and show it in the "container" if (DOM) { var viewer = document.getElementById(div2show); viewer.innerHTML = text; } else if(IE) { document.all[div2show].innerHTML = text; } } /* =============================================================== */ var ratingAction = { 'a.rater' : function(element){ element.onclick = function(){ var parameterString = this.href.replace(/.*\?(.*)/, "$1"); // onclick="sndReq('j=1&q=2&t=127.0.0.1&c=5'); var parameterTokens = parameterString.split("&"); // onclick="sndReq('j=1,q=2,t=127.0.0.1,c=5'); var parameterList = new Array(); for (j = 0; j < parameterTokens.length; j++) { var parameterName = parameterTokens[j].replace(/(.*)=.*/, "$1"); // j var parameterValue = parameterTokens[j].replace(/.*=(.*)/, "$1"); // 1 parameterList[parameterName] = parameterValue; } var theratingID = parameterList['q']; var theVote = parameterList['j']; var theuserIP = parameterList['t']; var theunits = parameterList['c']; //for testing alert('sndReq('+theVote+','+theratingID+','+theuserIP+','+theunits+')'); return false; sndReq(theVote,theratingID,theuserIP,theunits); return false; } } }; Behaviour.register(ratingAction);
plik rpc.php:
<?php //getting the values $vote_sent = $_REQUEST['j']; $id_sent = $_REQUEST['q']; //connecting to the database to get some information $query = mysql_query("SELECT ilosc_glosow, suma_glosow, srednia_glosow FROM ratings WHERE id_prod
uktu='$id_sent' "); $ilosc_glosow = $numbers['ilosc_glosow']; //how many votes total $suma_glosow = $numbers['suma_glosow']; //total number of rating added together and stored $suma_glosow = $suma_glosow + $vote_sent; // add together the current vote value and the total vote value $tense = ($count==1) ? "vote" : "votes"; //plural form votes/vote $nowa_ilosc_glosow = $ilosc_glosow + 1; $srednia_glosow = $suma_glosow/$nowa_ilosc_glosow; } if ($ilosc_glosow == 0) { mysql_query("INSERT INTO ratings SET id_produktu='$id_sent', ilosc_glosow='1', suma_glosow='$vote_sent', srednia_glosow='$vote_sent'"); } else { mysql_query("UPDATE ratings SET ilosc_glosow='$nowa_ilosc_glosow', suma_glosow='$suma_glosow', srednia_glosow='$srednia_glosow' WHERE id_produktu='$id_sent'"); } // setcookie('ratings', serialize($tablica), time()+3600); // these are new queries to get the new values! $newtotals = mysql_query("SELECT ilosc_glosow, suma_glosow, srednia_glosow FROM ratings WHERE id='$id_sent'"); $count = $numbers['ilosc_glosow'];//how many votes total $current_rating = $numbers['suma_glosow'];//total number of rating added together and stored $tense = ($count==1) ? "vote" : "votes"; //plural form votes/vote $new_back = "<ul class="unit-rating" style="width:100px;">n". "<li class="current-rating" style="width:". @number_format($current_rating/$count,2)*20 ."px;">Current rating.</li>n". "<li class="r1-unit">1</li>n". "<li class="r2-unit">2</li>n". "<li class="r3-unit">3</li>n". "<li class="r4-unit">4</li>n". "<li class="r5-unit">5</li>n". "<li class="r6-unit">6</li>n". "<li class="r7-unit">7</li>n". "<li class="r8-unit">8</li>n". "<li class="r9-unit">9</li>n". "<li class="r10-unit">10</li>n". "</ul>". "<p class="voted">$id_sent. Rating: <b>".@number_format($current_rating/$count,1)."</b>/5 (".$count." ".$tense." cast) ". "<span class="thanks">Thanks for voting!</span></p>";//show the updated value of the vote //name of the div id to be updated | the html that needs to be changed $output = "unit_long$id_sent|$new_back"; ?>
przykład tego o czym mówię: click