473,396 Members | 1,891 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 problem

5
Hi,
I’m developing a game, part of which is user being able to put on and take off cloths. The part of the image changing works perfectly, but the second function I added – to automatically change the „submit button” value from „Put on” to „take off” doesn’t work.
Here is complete JavaScript code:
Expand|Select|Wrap|Line Numbers
  1. function player_image(action,objekt) {
  2.   var http = false;
  3.   if(navigator.appName == "Microsoft Internet Explorer") {
  4.     http = new ActiveXObject("Microsoft.XMLHTTP");
  5.   } else {
  6.     http = new XMLHttpRequest();
  7.   }
  8.   http.abort();
  9.   http.open("GET", "ajax_server/game_server.php?page=" + action + "&objekt=" + objekt, true);
  10.   http.onreadystatechange=function() {
  11.     if(http.readyState == 4) {
  12.       document.getElementById('player_image').innerHTML = http.responseText;
  13.     }
  14.   }
  15.   http.send(null);
  16. }
  17.  
  18. function get_ajax_content(page,action,div) {
  19.   var obj = false;
  20.  
  21.   if(navigator.appName == "Microsoft Internet Explorer") {
  22.     obj = new ActiveXObject("Microsoft.XMLHTTP");
  23.   } else {
  24.     obj = new XMLHttpRequest();
  25.   }
  26.   obj.abort();
  27.   obj.open("GET", "ajax_server/game_server.php?page=" + page + "&action=" + action, true);
  28.   obj.onreadystatechange=function() {
  29.     if(http.readyState == 4) {
  30.       document.getElementById(div).innerHTML = obj.responseText;
  31.     }
  32.   }
  33.   obj.send(null);
  34. }
  35.  
Player_image function works, whereas get_ajax_content doesn’t.
And the HTML/PHP code for the div:
<a href="#" class="popout"><img src="images/things/'.$item['pilt'].'" border="0"><span>Amount: '.$items[$a][1].'<br /><div id="clothing_options">'.$clothing_options.'</div></span></a>
And the Javascript error message I get is: Line 30 Char: 5 Error: http is undefined…however there is NO http at line 30.
I have been struggling with that for long time and looks like I wount be finding a solution on my own, thereby I’ll ask here for help.
Thanks in advance
Dec 9 '07 #1
6 1158
gits
5,390 Expert Mod 4TB
hi ...

copy&paste is evil :) ... you have the following in your line 29:

Expand|Select|Wrap|Line Numbers
  1. if(http.readyState == 4) {
  2.       document.getElementById(div).innerHTML = obj.responseText;
  3. }
html has to be obj

kind regards
Dec 9 '07 #2
WSM
5
Hi,
Thanx :)
But now i get "syntax error" on line 1 :S
Dec 9 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

post the code you actually use ... so whats line 1 now?

kind regards
Dec 9 '07 #4
WSM
5
Hi,
That is the exact code Im currently using (cept that I fixed the error with variable name)...Line 1 is player image function declaration, which works just fine.
Dec 9 '07 #5
gits
5,390 Expert Mod 4TB
hi ...

repost it please. in case you simply changed http to obj that couldn't be the reason for an syntax error ... there should be another error ... don't you think so? :)

kind regards
Dec 9 '07 #6
WSM
5
Hi,
Yes, I know...thats what makes the error strange (at least for me) but just changing http to obj was the only change I made.
Here is the code I'm currently using:
Expand|Select|Wrap|Line Numbers
  1. function player_image(action,objekt) {
  2.   var http = false;
  3.   if(navigator.appName == "Microsoft Internet Explorer") {
  4.     http = new ActiveXObject("Microsoft.XMLHTTP");
  5.   } else {
  6.     http = new XMLHttpRequest();
  7.   }
  8.   http.abort();
  9.   http.open("GET", "ajax_server/game_server.php?page=" + action + "&objekt=" + objekt, true);
  10.   http.onreadystatechange=function() {
  11.     if(http.readyState == 4) {
  12.       document.getElementById('player_image').innerHTML = http.responseText;
  13.     }
  14.   }
  15.   http.send(null);
  16. }
  17.  
  18. function get_ajax_content(page,action,div) {
  19.   var obj = false;
  20.  
  21.   if(navigator.appName == "Microsoft Internet Explorer") {
  22.     obj = new ActiveXObject("Microsoft.XMLHTTP");
  23.   } else {
  24.     obj = new XMLHttpRequest();
  25.   }
  26.   obj.abort();
  27.   obj.open("GET", "ajax_server/game_server.php?page=" + page + "&action=" + action, true);
  28.   obj.onreadystatechange=function() {
  29.     if(obj.readyState == 4) {
  30.       document.getElementById(div).innerHTML = obj.responseText;
  31.     }
  32.   }
  33.   obj.send(null);
  34. }
  35.  
Dec 10 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
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...
5
by: Martin | last post by:
Hello NG, I've been doing some AJAX for a few weeks now. The basics worked fine so far, but now I've got the following problem which I can't solve: With AJAX you typically update/replace only...
3
by: Alok yadav | last post by:
I have an open IP and on that IP our main application is hosted. it uses ajax. in web.config file i have register ajax handlers. there are also other sites or project on that IP. now my problem is...
3
by: equazcion | last post by:
Hi, I have an image reference (IMG) in my page that changes depending on the value of a database field. Clicking the image triggers an Ajax call to change the database field (toggles the field...
7
by: tommurray | last post by:
Hi all Hope someone can help with the problem I am having as it is driving me nuts! I have the below script on my site the problem lies with passing through a url parameter in the below line...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
3
by: willl69 | last post by:
Hi All, Ive been having a problem of late with one of my sites that uses PHP5 / Ajax. The problem is that periodically the ajax functions lock up and it gets stuck in the loading phase of the...
2
by: majidtou | last post by:
Hi , We have an HTML page which is using AJAX. We make an AJAX call which retrieves a table with mutiple rows. We need to extend this functionality. In the table, we want to put a button on each...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.