Jump to content

[SOLVED] Loading Image?


wwfc_barmy_army

Recommended Posts

Hello, I have this code which i found on the internet and modified to my needs:

 

var xmlHttp

function showResult(str)
{
if (str.length==0)
{ 
document.getElementById("livesearch").
innerHTML="";
document.getElementById("livesearch").
style.border="0px";
return
}

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
} 

var url="blockfind.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 

function stateChanged() 
{ 

   
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById("livesearch").
innerHTML=xmlHttp.responseText;
document.getElementById("livesearch").
style.border="1px solid #A5ACB2";
} 


}



}

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;
}

 

Works fine. But i'm trying to add a loading image. I've tried adding;

 

 if (xmlHttp.readyState == 1) {
	   document.getElementById('livesearch').innerHTML = "<p align='center'><img src='ajax-loader.gif'><br /> Please Wait. This process may take a minute.</p>";
   }

 

Into the function stateChanged() but it doesn't do anything.

 

any ideas, suggestions or code?

 

Thanks.

Link to comment
Share on other sites

Try this revised code:

 

var xmlHttp = "";

function showResult(str){
if(str.length==0){
	document.getElementById("livesearch").innerHTML = "";
	document.getElementById("livesearch").style.border = "0px";
	return;
}

xmlHttp = GetXmlHttpObject()'

if(xmlHttp==null){
	alert("Browser does not support HTTP Request");
	return;
}

//Set the loading image.
document.getElementById('livesearch').innerHTML = "<p align='center'><img src='ajax-loader.gif'><br /> Please Wait. This process may take a minute.</p>";

//Call file with ajax.
var url = "blockfind.php?q="+str+"&sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

//Ready state change.
xmlHttp.onreadystatechange = function(){
	if(xmlHttp.readyState == 4){
		document.getElementById("livesearch").innerHTML = xmlHttp.responseText;
		document.getElementById("livesearch").style.border = "1px solid #A5ACB2";
	}
}
}

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.