Ajax Issue with IE

Discussion in 'JavaScript' started by adamjblakey, Mar 14, 2011.

  1. #1
    Hi,

    I am running the following code on my website:

    
    function showHint2(str)
    {
    if (str.length==0)
      { 
      document.getElementById("txtHint").innerHTML="";
      return;
      }
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
    	document.getElementById('course').innerHTML = xmlhttp.responseText;
        }
      }
      
      var params = [];
    
    params.push("q=" + str);
    params.push("u=" + document.getElementById("university").value);
    params.push("w=" + document.getElementById("university2").value);
    
    var url = "update-course.php?" + params.join("&");
      
      infoStr = str+"&u="+document.getElementById('university').value+"&w="+document.getElementById('university2').value;
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
    }
    
    Code (markup):
    
    require_once('init.php');
    	
    	//get the q parameter from URL
    	$choice=$_GET["q"];
    	$uni=$_GET["u"];
    	$uni2=$_GET["w"];
    	
    	if ($choice == 'Postgraduate'){
    		$year_of_study = "Postgraduate";
    	}else{
    		$year_of_study = "Undergraduate";
    	}
    	 
    	if ($uni2 == '-1'){ 
    	$query = mysql_query("SELECT * FROM universities WHERE year_of_study = '$year_of_study' AND university = '$uni'");
    	}else{
    	$query = mysql_query("SELECT * FROM universities WHERE year_of_study = '$year_of_study' AND university = '$uni2'");	
    	}
    	while ($row = mysql_fetch_array($query))
    			{
    	 	 	 print "<option value='" . $row['course'] . "'>" . $row['course'] . "</option>";
    			}
    		
    
    PHP:
    Which works fine on all browsers except IE. Does anyone have any ideas why this would not work on IE?

    Cheers,
    Adam
     
    adamjblakey, Mar 14, 2011 IP
  2. tradeout

    tradeout Peon

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Maybe a problem with the HTML.
    PM me more details.

    Will have you sorted in minutes. :)
     
    tradeout, Mar 17, 2011 IP
  3. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Is I.E showing a javascript error? If so, then what does the error say and what line... As far as I can tell, the code looks fine. The only thing I can think of is for you to declare xmlhttp at the start of your code (before function showHint2) like:
    
    var xmlhttp;
    
    Code (markup):
     
    camjohnson95, Mar 18, 2011 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    I tested the same code in IE8 and it worked
     
    camjohnson95, Mar 18, 2011 IP