jasper182 Posted January 14, 2007 Share Posted January 14, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/34081-optimizing-my-ajax/ Share on other sites More sharing options...
ober Posted January 14, 2007 Share Posted January 14, 2007 We can't help much without seeing the code. Quote Link to comment https://forums.phpfreaks.com/topic/34081-optimizing-my-ajax/#findComment-160653 Share on other sites More sharing options...
jasper182 Posted January 14, 2007 Author Share Posted January 14, 2007 Well, mainly I have functions such as this onevar 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. Quote Link to comment https://forums.phpfreaks.com/topic/34081-optimizing-my-ajax/#findComment-160705 Share on other sites More sharing options...
irken Posted January 15, 2007 Share Posted January 15, 2007 How about something like.. eye candy.[code]httpvar = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34081-optimizing-my-ajax/#findComment-161134 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.