PDA

View Full Version : AjAx problem in IE????



saikishore
09-07-2009, 01:49 PM
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>
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...

JShor
09-07-2009, 04:20 PM
Are you running it on a server or your computer? THe only known problem IE can have with Ajax that's different from other browsers is an access denied error.