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
https://forums.phpfreaks.com/topic/133168-solved-loading-image/
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
https://forums.phpfreaks.com/topic/133168-solved-loading-image/#findComment-692593
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.