Jump to content

readyState in IE


duframe

Recommended Posts

I have spent the entire day searching, trying, pulling out my hair, and I cannot yet find a solution. I am rather new to javascript, so I'm sure that my verbiage might be wrong here.

 

I am using jquery for a window box. I am also using an XMLHttpRequest/ActiveXObject request to pull dynamic content from the db. Everything works perfectly in Firefox and other browsers except for IE (using v8). onClick of a link will call the script below and load that into a div called iteminfo. Only in IE, the iteminfo content does not load until the mouse is moved off of the screen (out of the display area of the browser) or you open another application/window and come back to IE, and at that point it will load the content into the div.

 

I've tried setInterval and setTimeout as a delay to help give IE time to download the dynamic content. I've tried using a loop if readyState!= 4 then loop through the function stateChanged until it's == 4, but just turns out to be an endless loop.

 

I look forward to your suggestions.

 

 

 

 

 

var xmlHttp;

 

function showResult(rid, iid)

{

document.getElementById("iteminfo").style.display="block";

 

 

xmlHttp=GetXmlHttpObject();

 

if (xmlHttp==null)

{

alert ("Your browser does not support features used on this page. You may need to download the latest version of Javascript. You will not be able to view the pictures and descriptions for each item.");

return;

}

 

var url="pathtofilegoeshere.php";

url=url+"?rid="+rid;

url=url+"&iid="+iid;

 

 

xmlHttp.open("GET",url,true);

 

xmlHttp.onreadystatechange=stateChanged;

 

xmlHttp.send(null);

}

 

function stateChanged()

{

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

{

document.getElementById("iteminfo").innerHTML=xmlHttp.responseText;

 

}

 

 

 

 

}

 

function GetXmlHttpObject()

{

var xmlHttp=null;

try

{

// Firefox, Opera 8.0+, Safari

xmlHttp=new XMLHttpRequest();

}

catch (e)

{

// Internet Explorer

try

{

xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

}

}

return xmlHttp;

}

Link to comment
Share on other sites

Try this:

var xmlHttp = GetXmlHttpObject();;
function showResult(rid, iid){
document.getElementById("iteminfo").style.display="block";
if (xmlHttp==null){
	alert ("Your browser does not support features used on this page. You may need to download the latest version of Javascript. You will not be able to view the pictures and descriptions for each item.");
	return;
}
var url="pathtofilegoeshere.php";
url=url+"?rid="+rid;
url=url+"&iid="+iid;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.send(null);
}

function stateChanged(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
	document.getElementById("iteminfo").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject(){
var xmlHttp=null;
try{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
}catch (e){
	// Internet Explorer
	try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}catch (e){
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
}
return xmlHttp;
}

 

if it makes no difference then try this jQuery version:

jQuery(function($){
var resultDiv = $("#iteminfo");
function showResult(rid, iid){
	var url = "pathtofilegoeshere.php?rid="+rid+"&iid="&iid;
	$.get(url, function(data){
		if(data.length > 0){
			resultDiv.html(data);
		}else{
			alert("No results returned for iid: '"+iid+"' and rid:'"+rid+"'");
		}
	});
}
});

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...