Coder Profile - Show off your skills, get a coder profile.
 
 
 
  
Posted: 1.84 Year Ago 

Seachmall
Ireland
Contrib Level: 9
Total Posts: 965
CODE: Ajax Code Copy / Restore  ::  Remove Scroll Bars
  1.  
  2. function ajax(url, get_value, post_value){
  3.  
  4.     this.url = url ? url : "http://www.somesite.com/getsomething.php" ;
  5.  
  6.     this.get_value = get_value;
  7.  
  8.     this.post_value = post_value;
  9.  
  10.     this.response = null;
  11.  
  12.  
  13.  
  14.  
  15.  
  16.     try{
  17.  
  18.     // Firefox, Opera 8.0+, Safari
  19.         this.xmlHttp = new XMLHttpRequest();
  20.  
  21.      }
  22.  
  23.     catch (e){
  24.  
  25.     // Internet Explorer
  26.  
  27.         try{
  28.  
  29.             this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  30.  
  31.         }
  32.  
  33.           catch (e){
  34.  
  35.             this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  36.  
  37.         }
  38.  
  39.       }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.     this.getData = function(wat){
  46.  
  47. // alert(wat);
  48.  
  49.         if (this.xmlHttp.readyState == 4){
  50.  
  51.             return this.xmlHttp.responseText;
  52.  
  53.         }else if(this.xmlHttp.readyState == 1 || this.xmlHttp.readyState == 2 || this.xmlHttp.readyState == 3){
  54.  
  55.             return this.xmlHttp.readyState;
  56.  
  57.         }
  58.  
  59.     }
  60.  
  61.  
  62.  
  63.  
  64.  
  65.     this.url += "?ran=" + Math.random() + "&get=" + get_value;
  66.  
  67.     this.xmlHttp.onreadystatechange = this.getData("trapped");
  68.  
  69.     this.xmlHttp.open("POST",this.url,true);
  70.  
  71.     this.xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  72.  
  73.     this.xmlHttp.send(post_value);
  74.  
  75.  
  76. }
  77.  
CODE: Creating Object Copy / Restore  ::  Remove Scroll Bars
  1.  
  2.     ajaxController = new ajax(null, get_value, post_value);
  3.  
  4.     alert(ajaxController.getData("free") );
  5.  
All fairly straightforward except for one thing, see that alert(wat) in ajax.getData()? If I comment that out it returns 1 (the readystate), if I leave it to execute the response returns what it's supposed to (i.e. the readystate reaches 4).

The only difference between commenting out the alert() and leaving it in is the amount of time before the script reaches the if/else statement. In other words the script is executing too fast meaning it doesn't allow the readystate reach 4 before it moves on. Any way around this? It's a real pain in the ass, it seems like it should work but won't. Any help appreciated.
Page 1 of 1
 
 
Latest News About Coder Profile
Coder Profile Poll
Which sounds better on your coder profiles, and makes more sense to you (think twitter, facebook, etc)?

Followers / Following
Fans / Following
Fans / Fan Of


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
3.49 Years Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2012, Scott Thompson, All Rights Reserved