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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    xmlhttprequest.open problems

    Code:
    function http() {
    	if(!window.ActiveXObject && window.XMLHttpRequest) {
    		//Firefox, Opera, Safari, Google Chrome
    		this.h = new XMLHttpRequest();
    	}
    	if(window.ActiveXObject) {
    		//If it's internet explorer
    		this.h = new ActiveXObject("Microsoft.XMLHTTP" || "Msxml2.XMLHTTP" || "Microsoft.XMLHTTP");
    	}
    }
    
    http.prototype.requestHandler = function(params) {
    	this.h.open('get','server/ajaxtest.php?params='+params,true);
    	this.h.send(null);
    	response = this.h.onreadystatechange;
    }
    
    http.prototype.response = function(elem) {
    	if(this.h.readyState == 4 && this.h.status == 200) {
    		document.getElementById(elem).innerHTML = this.h.responseText;
    	}
    }
    
    function ajax(params,obj) {
    	ajaxRequest = new http();
    	ajaxRequest.requestHandler(params);
    	ajaxRequest.response(obj);
    }
    When setting the asynchronous to true firefox and other browser other than internet my code doesn't work. However if it's turn to false this code this code works. Why is this?

    Thanks,
    Jon W
    Last edited by Jon W; 08-23-2010 at 10:27 PM.

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Hmm... I've still not yet figured this out. So if anyone has any idea why this is then that would be wonderful.

    Thanks,
    Jon W

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,280
    Thanks
    12
    Thanked 342 Times in 338 Posts
    synchronous requests are not handled via onreadystatechange.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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