// this is the client side of the AJAX voting script // note that the user_id|date_created are encoded here, and will be verified. // this function receives the vote button submit event // vote value v, page_id pid function sendVote(v,pid) { // var v = document.pgform.getElementByID(obj).value; // alert("You voted "+v+" on item "+pid+"."); getXML(pid,v); } // quick wrapper for getElementById: function _obj(id) { return document.getElementById(id); } // quick wrapper for XML parsing getElementsByTagName: // doc is an XMLResponse documentElement function _xdoctag(doc,id) { var child=doc.getElementsByTagName(id)[0]; if (!child){ alert(id+" not found."); return ""; } child = child.firstChild; return (!child) ? "" : child.data; } // write html to the DOM object given by id // if dbg=1, add a debug button (if global debug=1) // if op=+, add to current value function htmlPut(id, html) { var obj = _obj(id); // alert("htmlPut("+id+", "+html+")"); if (obj!=null){ obj.innerHTML = html; } } ////////////// //---------- XML METHODS ////////////// // // this is called when an XML block is done loading // function xmlReturn (){ if (req.readyState == 4) { // if req shows "complete" if (req.status == 200) { // if status="OK" // ...processing statements go here... // showStatus("Ready"); // update status bar // // for voting, it will return id,your_vote,total_vote var err = _xdoctag(req.responseXML.documentElement,"error"); if (err>""){ alert(err); } else { var id = _xdoctag(req.responseXML.documentElement,"page_id"); // var yours = _xdoctag(req.responseXML.documentElement,"your_vote"); var vcount = _xdoctag(req.responseXML.documentElement,"vote_count"); var total = _xdoctag(req.responseXML.documentElement,"total_vote"); // debugPut("xmlReturn (): Method="+myMethod); htmlPut("vote"+id, vcount); htmlPut("total"+id, total); htmlPut("divv"+id, yours); } } else { alert("There was a problem retrieving the XML data:\n" + req.status + "\n" + req.statusText); // showStatus(req.statusText); // update status bar } } } // // this is called to initiate an XML request // xtype = type of data to get: Script|Node (must be capitalized, since it's used in an URL) // id = id of object to retrieve // can have extra parameters tacked onto id in &name=value format // function getXML(id,v) { var URL = "http://www.civilSimian.com/new/vote.fn.php?id="+id+"|"+v+"|"+dtc; // var URL = "http://69.94.102.86/civilsimian.com/new/vote.fn.php?id="+id+"|"+v+"|"+dtc; // alert("Sending AJAX call:\n"+URL); var waitmsg = "Waiting for XML."; debugtxt = ""; // clear debug buffer // debugPut(URL); // update status bar if (window.XMLHttpRequest) { // branch for native XMLHttpRequest object req = new XMLHttpRequest(); } else if (window.ActiveXObject) { // branch for IE/Windows ActiveX version req = new ActiveXObject("Microsoft.XMLHTTP"); } else { // debugPut("No request object."); // update status bar return; } if (req) { req.onreadystatechange = xmlReturn; // showStatus(waitmsg); // update status bar req.open("GET", URL, true); req.send(null); } }