473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Ajax Problems

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>

Feb 19 '06 #1
3 1299
PFA(.)(.)Coder wrote:
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";

There isn't an element with an id of whatever is in mana[0]. Stick in an
alert and see what it is.

--
Ian Collins.
Feb 19 '06 #2

"Ian Collins" <ia******@hotmail.com> wrote in message
news:11***************@drone2-svc-skyt.qsi.net.nz...
Line 57 is : document.getElementById(mana[0]).style.width = mana[1]+"px";

There isn't an element with an id of whatever is in mana[0]. Stick in an
alert and see what it is.

--
Ian Collins.


Thanks Ian, but I have checked the mana page manually and it is outputting
the correct ID reference, and the element does exist in the html. I did put
the output of mana in an alert, and it popped up and empty box.

Feb 21 '06 #3
PFA(.)(.)Coder wrote:
"Ian Collins" <ia******@hotmail.com> wrote in message
news:11***************@drone2-svc-skyt.qsi.net.nz...
Line 57 is : document.getElementById(mana[0]).style.width = mana[1]+"px";


There isn't an element with an id of whatever is in mana[0]. Stick in an
alert and see what it is.

--
Ian Collins.

Thanks Ian, but I have checked the mana page manually and it is outputting
the correct ID reference, and the element does exist in the html. I did put
the output of mana in an alert, and it popped up and empty box.

Did you try alert(mana[0]) or alert(document.getElementById(mana[0]))?

If you got an emty box then either mana[0] is an empty string, or the
element with an id of mana[0] does not exist. More likely the former.

Try you page in Firefox with the JavaScript console open, you will get
better error messages than you get with IE.

--
Ian Collins.
Feb 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Yarco | last post by:
I want to use "Ajax" to create my web for hobby. But i don't know whether "Ajax" is mature... And what about with php? Someone have experience on it? ....
4
by: bobzimuta | last post by:
I'm creating a simple AJAX library. It's an object that will return an array containing the response text or xml. I'm trying to find a way to assign the response as a property of the object, but...
8
by: needin4mation | last post by:
I understand this is a asp.net group, but thought I would post this here for comments. I admit I have used this post in another group, but it has less traffic. Here's to hoping I'm just blind to...
11
by: John Smith | last post by:
I am using Ajax to refresh a DIV area by setting the innerHTML=request.responseText in the usual manner. in the response text I have a <SCRIPT> tag in line, but this is not executed. Is there a way...
0
by: melledge | last post by:
Ajax Developers' Day added to XTech 2006 agenda XTech 2006 - 17-19 May - Hotel Grand Krasnopolsky - Amsterdam, The Netherlands
10
by: Steve | last post by:
I need to build a very dynamic client and would be interested in knowing the pros and cons of using JSF and Ajax to accomplish this. Thanks. Steve
0
by: melledge | last post by:
Ajax Developers' Day to Kick Off XTech 2006 Conference Industry experts offer insight into next generation of the Web ALEXANDRIA, VIRGINIA, USA - April 25, 2006 - In response to the rapidly...
31
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked...
23
by: Allan Ebdrup | last post by:
I hava an ajax web application where i hvae problems with UTF-8 encoding oc chineese chars. My Ajax webapplication runs in a HTML page that is UTF-8 Encoded. I copy and paste some chineese chars...
3
by: =?Utf-8?B?bWNpbWFnaW5n?= | last post by:
We have recently applied AJAX to our web site, nothing particularly fancy, just some update panel, progress images and collapsible panels, just the basics to improve the user experience. The...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.