Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delay with AJAX request

Status
Not open for further replies.

emozley

Technical User
Jan 14, 2003
769
0
0
GB
Hi,

I have a page (written in ASP) that displays a series of titles. When you click a title it unhides a div and then makes an AJAX request to look up more information about that particular title and then displays it in the div.

For some reason when I click the link there is quite a long pause (about 4 seconds on average) before it displays the text but on the other hand if I run the ASP on it's own eg showcsritem.asp?CSRPostID=5 it displays almost immediately.

Has anyone ever come across this sort of problem before?

Thanks

Ed
 
Hello,

Could you post your AJAX code? There is a possiblity that your script uses the javascript setTimeout function and has been set to around 4000 milliseconds, which needs to be lowered.

Chris
 
Here's the code

Code:
var xmlhttp

function showItem(CSRPostID)
{
if (CSRPostID.length==0)
  {
  document.getElementById("mypopup2").innerHTML="";
  return;
  }
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }
var url="showcsritem.asp";
url=url+"?CSRPostID="+CSRPostID;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById("mypopup2").innerHTML=xmlhttp.responseText;
  }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

It's the same code I've used elsewhere and not had any performance issues - if need be I can post the other scripts; there are hidden divs and server side includes and stuff which might complicate things slightly but at the moment it's a real puzzler!

Thanks

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top