Web Analytics Made Easy -
StatCounter AJAX in IE - CodingForum

Announcement

Collapse
No announcement yet.

AJAX in IE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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]

    Comment


    • #3
      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.

      Comment

      Working...
      X