I am trying to use ajax to create a voting system. I used the tutorial by
Rasmus found here:
http://rajshekhar.net/blog/archives/...-Tutorial.html
It's pretty much a cut-n-paste and the method updateCount() works great, no
issues.
(See script below)
I made an identical method, updateMana, and cannot get it to work.
In the updateMana method, the alert() shows that the correct info is being
sent to mana.php.
Browsing the mana.php page directly will output the correct data, in the
correct format.
But the browser reports an error:
Line: 57
char: 5
Object required
Code: 0
Line 57 is : document.getElementById(mana[0]).style.width = mana[1]+"px";
The report div is at top of page, and when the script is executed, I can see
it drop the other elements down, but there is no text in the box at all.
My first attempt with Ajax, hopefully someone can help me out!!
--Ridge
the script:
<script language="JavaScript" type="text/javascript">
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function updateCount(action){
http.open('get', 'ninja.php?link_id='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}
//Begin my methods
function updateMana(action,vari,session_id) {
http.open('get',
'mana.php?site='+escape(action+'&vote='+vari+'&ses sion='+session_id));
http.onreadystatechange = handleMana;
http.send(null);
alert(action + " - " + vari + " - " + session_id); //Show what is being
sent, it is correct!!!
}
function handleMana() {
if(http.readyState == 4){
var myresponse = http.responseText;
var mana = new Array();
if(myresponse.indexOf('|' != -1)) {
mana = myresponse.split('|');
if(mana[1] == "Voted!"){
document.getElementById("report").innerHTML = 'You have already voted
today!';
}else{
document.getElementById("report").innerHTML = myresponse; //Trying to
see what is returned, its EMPTY, not undefined
document.getElementById(mana[0]).style.width = mana[1]+"px";
}
}
}
}
</script>