Jump to content

Optimizing my AJAX


jasper182

Recommended Posts

Right now I am working with a web app that makes numerous calls to a MySQL database and sends data back and forth constantly.  The data is all text, so it isn't very large, but it still have more of a delay then I would like.  I am looking for any tips/advice/references you can give me on optimizing AJAX code so that it will run faster and give the user a smoother experience.  I've worked with AJAX over the past year, so I have the basics down but now I'm hoping to get into it deeper to improve my skills.  Thanks.
Link to comment
Share on other sites

Well, mainly I have functions such as this one

var OLDhttpvar;
var httpvar;
function getUserList() {
if(window.XMLHttpRequest){
httpvar = new XMLHttpRequest();
}
else
{
httpvar = new ActiveXObject("Microsoft.XMLHTTP");
}
var params;
params = "username=Jasper&project=12"

httpvar.open('POST', 'showUserList.php', true);
httpvar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpvar.setRequestHeader("Content-length", params.length);
httpvar.setRequestHeader("Connection", "close");
httpvar.send(params);

httpvar.onreadystatechange = function() {
if (httpvar.readyState == 4) {
if(OLDhttpvar != httpvar.responseText)
{
document.getElementById("memberList").innerHTML = (httpvar.responseText);
OLDhttpvar = httpvar.responseText;
}
}
};

delete params;

}
setInterval("getUserList()",250);

I have about 6-7 of these going, all are updating between 250 and 5000 milliseconds, and thats really it. 
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.