PDA

View Full Version : AJAX in IE


can_i_say
04-09-2009, 09:26 AM
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.


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?

A1ien51
04-12-2009, 02:33 PM
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

bdl
04-12-2009, 03:33 PM
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.