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
https://forums.phpfreaks.com/topic/34081-optimizing-my-ajax/
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
https://forums.phpfreaks.com/topic/34081-optimizing-my-ajax/#findComment-160705
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.