Hi frnds...

I am doing poll in AJAX..this is first time i am using AJAX.. The below code is working fine in mozilla, chrome...but not working in IE....plz check the below code...and change the code as correctly..i think problem in object creation in IE..

<script>
 //VOTE POLL -------------------------------------
    function makeVote(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertVote;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertVote() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('vote_msg').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
 
   function submit_vote(obj) {
	  var vote_value = getCheckedValue(document.forms['vote-form'].elements['opt']);
      var poststr = "poll_id=" + encodeURI( document.getElementById("poll_id").value ) +
                    "&voteid=" + encodeURI( vote_value);				
      makeVote('vote.php', poststr);
   }
</script>

        
<script type="text/javascript">

	function getxmlhttp(){
		var page_request = false;
		if (window.XMLHttpRequest){
			return xmlhttp = new XMLHttpRequest();
		}else if (window.ActiveXObject){
			try {
				return xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}catch (e){
				try{
					return xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}catch (e){}
			}
		}else{
			return false
		}
	}
	
	function getpage(url, container){
		xmlhttp = getxmlhttp();
		xmlhttp.open('GET', url);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				document.getElementById(container).innerHTML = xmlhttp.responseText;
			}else{
			document.getElementById(container).innerHTML = "<h3><font color=#1B1B1B>Loading.....</font></h3>";
				//document.getElementById(container).innerHTML = '<div style="text-align:center;"><img src="images/ajax-loader.gif" /></div>';
			}			
			//alert(xmlhttp.status);
			//document.getElementById(container).innerHTML = xmlhttp.responseText;
		}
		xmlhttp.send(null);
	}
	
	
</script>

Try replacing your first function with the following:

//VOTE POLL -------------------------------------
    function makeVote(url, parameters) {
      var http_request;
      try{
		// Opera 8.0+, Firefox, Safari
		http_request = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("You need ajax enabled.");
				return false;
			}
		}
	}
 
      http_request.onreadystatechange = alertVote;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

Hope that helps

Hello Crwan..

Thanks for ur quick reply....

I have been changed..but no output...i got error on page(Unknown Runtime Error on line 5)... ...at the bottom of the page status...the page not redirecting frm one page to another page...it displays LOADING..... thats it...Plz do this...

Thanks once again..
Saritha..

I would suggest following an ajax tutorial because your syntax looks a little weird. One that I know of is the tizag tutorials but a google search will reviel more.

I would suggest following an ajax tutorial because your syntax looks a little weird. One that I know of is the tizag tutorials but a google search will reviel more.

K Sir..
I will try...

Thanks...

Member Avatar for diafol

Have you tried using a library such as 'prototype' to do all the object handling for you? I find it saves hours. I hate IE with a vengeance and the less I have to mess with targeted browser code, the better.

Have you tried using a library such as 'prototype' to do all the object handling for you? I find it saves hours. I hate IE with a vengeance and the less I have to mess with targeted browser code, the better.

Hi Ardav,

I dont know abt this 'prototype'...plz tell me how can i implement this ... i struggling from last 5 days..still i didnt get this ...i am getting 'ERROR ON THIS PAGE' AT THE BOTTOM OF THE PAGE STATUS.... it displays ' unknown runtime error'....

it is works fine in MOZILLA, CHROME...ONLY PROBLEM IN IE....PLZ MODIFY THE CODE IF U KNOW..
thanks in advance....

Look, i've found this reliable! profitable forex system

Member Avatar for diafol

Prototype: prototypejs.org

You just place the js file into your page (and any js files holding your custom scripts). I find it really easy to update certain html elements via the Ajax.Updater command and get json encoded info from the ajax object. Cross-browser nonsense is handled by the library.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.