Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onreadystate working only with alert statement

    In my app I use some autocomplete functionality.

    In the code below, the the readyState function worke only when I have an alert statement in it. I can't figure out why this should work...
    Please help!!!

    Code:
    var u = "http://localhost:8080/ReiseloggSpring2/autoGetCities.do?city=b";
    var reqObj = new AjaxRequest(u);
    var r = reqObj.getRequest();
    
    function AjaxRequest(urlStr){ 
      var req; 
      var url = urlStr;
     this.status = new Boolean("false");
      this.initRequest = initRequest;
      this.getRequest = getRequest;
      this.onreadystate = onreadystate;
      
      function getRequest(){
        req = this.initRequest();
        req.open("GET", url, true);
        req.onreadystatechange = this.onreadystate;    
        
        req.send(null);
        
        return req;
      }
      
      function onreadystate(){ alert("IN READYSTATE")
         
        if (req.readyState == 4) {
          if (req.status == 200) {
            if( req.responseText.length > 0){
              this.status = "true";
            }else{
              this.clearTable();
              this.completeTable.style.display="none";
            }
          }else if (req.status == 204){
            this.clearTable();
          }
        } 
      }
      
      function initRequest() {
        if (window.XMLHttpRequest) {
          return new XMLHttpRequest();
        } else if (window.ActiveXObject) {
          return new ActiveXObject("Microsoft.XMLHTTP");
        }
      }
    }

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    = this.onreadystate;
    needs to be loose the this

    = onreadystate;

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •