NetworkGhost
IS-IT--Management
Got a quick question. Got some slowness in my javascript that I dont experince when I go to the page itself. Hopefully someone can point me in the right direction:
Here is the script:
When I render the URL the script is calling it loads quite quickly. When I use the javascript AJAX method it takes a few seconds. Was wondering if there is something Im missing or a better way to accomplish.
Here is the script:
Code:
var xmlHttp
function showResult(str)
{
if (str.length==0)
{
document.getElementById("livesearch").
innerHTML="";
document.getElementById("livesearch").
style.border="0px";
return
}
xmlHttp=new XMLHttpRequest();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="livesearch.php"
url=url+"?q="+str
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("loading").
innerHTML="";
}
else {
document.getElementById("loading").
innerHTML="<img src='121339176329.gif' height='400' width='400' >";
}
}
When I render the URL the script is calling it loads quite quickly. When I use the javascript AJAX method it takes a few seconds. Was wondering if there is something Im missing or a better way to accomplish.