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

Thread: AJAX in IE

  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AJAX in IE

    I'm having some trouble with AJAX/PHP and IE. My scripts work in all other major browsers (Firefox, Safari, Opera, Chrome) but don't work in IE, and I'm not sure why as I'm fairly new to JavaScript.

    Code:
    var xmlHttp;
    
    function contactRequest(user_id, requested_by_id, action, i){
    	xmlHttp=GetXmlHttpObject();
    
    	var url="ajax/requestContact.php";
    	url=url+"?user_id="+user_id;
    	url=url+"&requested_by_id="+requested_by_id;
    	url=url+"&action="+action;
    
    
    	xmlHttp.onreadystatechange= function() {
            if (xmlHttp.readyState==4)
                if (xmlHttp.status==200)
                    stateChanged2(i); }
    
    	xmlHttp.open("GET",url,true);
    	xmlHttp.send(null);
    }
    
    
    function stateChanged2(tag){
    
     		document.getElementById('contactForm').style.display = 'none';
    		document.getElementById("contact"+tag).innerHTML=xmlHttp.responseText;
    }
    
    function GetXmlHttpObject(){
    	var xmlHttp=null;
    
    	try {
    	 // Firefox, Opera 8.0+, Safari
    	 xmlHttp=new XMLHttpRequest();
     	}
    
    	catch (e) {
    	 	//Internet Explorer
    	 		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    
     	}
    
    return xmlHttp;
    }
    When the button calling the function is clicked the div is hidden but the PHP script ajax/requestContact.php appears not be to be invoked in IE. Any pointers?

  • #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
    Have you added alert statments to see if the code is being called and see if it makes through the functions. Is the call coming back as something other than 200?

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

  • #3
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Code:
    xmlHttp.onreadystatechange= function() {
            if (xmlHttp.readyState==4)
                if (xmlHttp.status==200)
                    stateChanged2(i); }
    This is really confusing. You should clean this up by explicitly defining blocks and using some proper indentation.

    Where is i defined? I know that IE can have a problem with vars that are not explicitly defined, this may be the issue.


  •  

    Posting Permissions

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