www.webdeveloper.com
Results 1 to 5 of 5

Thread: IE Ajax Problem

  1. #1
    Join Date
    Jan 2005
    Location
    USA
    Posts
    352

    Thumbs down IE Ajax Problem

    Ok, so this script seems to work perfectly with Firefox, Safari, etc...but not IE.

    I have the proper ActiveX stuff in there so it SHOULD work with IE...but alas, it doesn't.

    Here's the javascript for my ajax stuff:

    Code:
    var XMLHttpRequestObject = false;
    
    // Instantiate the XMLHttpRequest object if Mozilla/Netscape/etc.
    if (window.XMLHttpRequest) {
        XMLHttpRequestObject = new XMLHttpRequest();
    }
    
    // Instantiate the ActiveXObject if MSIE
    else if (window.ActiveXObject) {
        XMLHttpRequestObject = new ActiveXObject('Microsoft.XMLHTTP');
    	//document.write('Using IE');
    }    
        
    function getData(dataSource, divID) {
        if(XMLHttpRequestObject) {
            var obj = document.getElementById(divID);
            XMLHttpRequestObject.open('GET', dataSource);
    
            XMLHttpRequestObject.onreadystatechange = function () {
                /* Pretty animated loading image... */
                obj.innerHTML = '<img src="loading.gif" alt="Loading..." />';
    
                if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
                    obj.innerHTML = XMLHttpRequestObject.responseText;
                }
    			else{
    				document.write('somethings wrong with readystate or status');
    				document.write(XMLHttpRequestObject.readyState);
    				//document.write(XMLHttpRequestObject.status);
    				//document.write(XMLHttpRequestObject.responseText);
    			}
            }
    
            XMLHttpRequestObject.send(null);
        }
    }
    I noticed that the readyState never moves past '1', which is "Loading"...

    Anyone have any ideas?
    I'm very confused.

    Thanks

  2. #2
    Join Date
    Feb 2006
    Posts
    2,927
    You are missing the parameter that puts the A in Ajax-

    XMLHttpRequestObject.open('GET', dataSource,true);

    Code:
    function AJ(){
    	var obj;
    	if (window.XMLHttpRequest) obj= new XMLHttpRequest();
    	else if (window.ActiveXObject){
    		try{
    			obj= new ActiveXObject('MSXML2.XMLHTTP.3.0');
    		}
    		catch(er){
    			try{
    				obj=new ActiveXObject("Microsoft.XMLHTTP");
    			}
    			catch(er){
    				obj=false;
    			}
    		}
    	}
    	return obj;
    }
    Last edited by mrhoo; 06-14-2007 at 01:08 PM.

  3. #3
    Join Date
    Jan 2005
    Location
    USA
    Posts
    352
    Alright, got that added. It still doesn't work though .

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,506
    well your using document.write to output to the current page. document.writeln should be used as I believe that your overwriting the page and hence killing off your Ajax.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  5. #5
    Join Date
    Mar 2007
    Location
    Orlando
    Posts
    670
    The "true" in the open function does not need to be passed. The default is an asynchronous transaction.
    However you are write about using document.write(). The readyState will change numerous times during an Ajax call. So what you are doing is checking to see if the readyState == 4 and status == 200 which is correct, but you write out to the page with your else block so you never get your response. Get rid of the else block and it will work fine.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles