469,609 Members | 2,189 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

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 1060
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

Post your reply

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

Similar topics

4 posts views Thread by bobzimuta | last post: by
31 posts views Thread by Tony | last post: by
5 posts views Thread by Martin | last post: by
3 posts views Thread by Alok yadav | last post: by
6 posts views Thread by =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post: by
3 posts views Thread by willl69 | last post: by
reply views Thread by Solution2021 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.