Ajax not working in Internet Explorer!

Hi all,

The following Ajax script is working in all the browser expect Internet explorer.



var xmlHttp;

function GetXmlHttpObject(){
	var xmlHttp;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	return xmlHttp;
}




///Supplier Master
function Getsuppliercode(){

	var SupplierGroup = document.getElementById('supplier_group').value;
	
	if(SupplierGroup == ''){
		document.getElementById('suppliercode').value = '';
		document.getElementById('suppliercode').innerHTML ='<option value="">--- SELECT ---</option>';
	}
	else{
		
		xmlHttp=GetXmlHttpObject()
		var queryString = "?supplier_group="+SupplierGroup;
		//alert (queryString);
		xmlHttp.onreadystatechange=function()
		{ 
				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
				var dep = ''; 
				var result = xmlHttp.responseText;
				//document.getElementById('suppliercode').value = '';
				document.getElementById('suppliercode').innerHTML ='<option value="">--- SELECT ---</option>';
				//document.getElementById('empname').value = '';
				var re = result.split(',');
				for(i=0;1<re.length;i++){
					if(re[i] == ''){
						break;
				}
				//alert("<option value="+re[i]+">"+re[i]+"</option>")
				document.getElementById('suppliercode').innerHTML += "<option value="+re[i]+">"+re[i]+"</option>";	
				}									
			} 
		}
		//alert ("getsuppliercode.php" +queryString);
		xmlHttp.open("GET","getsuppliercode.php" + queryString,true);
		xmlHttp.send(null);
		
		return true;
	}		
}

Could somebody tell me why it is not working in IE.

Thank you.

Is there any error message are you receiving while accessing your script in IE? and also provide us the IE version which you are using?

No I am not getting error message, while i am accessing the page using IE the combo box not showing the result instead it shows an empty combo box but i am getting result while accessing with firefox. I am using IE7.

Thank you for you help.

Do some more debugging. Check the value of responseText for example. Check the values of your other variables.

One thing I’ll throw out at you, is that IE is more aggressive caching ajax requests than some browsers. Make sure your web server is sending appropriate http headers along with the response, to indicate to the browser not to cache the response. This is the prefered way. The ugly way is to append an ever changing value to the query string for each request, like the time in miliseconds. Well, assuming you don’t want it cached.

In any case, clear your cache. The browser might have retained a previous version from while you were developing.