EchoFool Posted August 10, 2010 Share Posted August 10, 2010 Hey, I have an ajax script for a chat room but wanted some one who knows ajax to tell me if there is a way i can increase its efficientcy if at all...as it calls a php script all the time to check for new messages - was wondering if my method of calls can be improved? Here is my script: function createRequestObject() { var ro; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ ro = new ActiveXObject("Microsoft.XMLHTTP"); }else{ ro = new XMLHttpRequest(); } return ro; } var http = createRequestObject(); function sndReq() { http.open('get', 'chatcheck.php'); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() { if(http.readyState == 4){ var response = http.responseText; var update = new Array(); if(response == '1') { updateShouts(); } } } function sendMessage() { $.ajax({ type: "POST", url: "chatpost.php", async: false, data: "message="+$("#myMessage").val(), }); $("#myMessage").val(""); return false; } function updateShouts(){ $('#chatArea').load('chat.php'); } setInterval( "sndReq()", 1000 ); Quote Link to comment https://forums.phpfreaks.com/topic/210278-if-this-most-efficient/ Share on other sites More sharing options...
trq Posted August 10, 2010 Share Posted August 10, 2010 Your code is pretty mixed up, switching between vanilla Javascript and jQuery. Why? Quote Link to comment https://forums.phpfreaks.com/topic/210278-if-this-most-efficient/#findComment-1097391 Share on other sites More sharing options...
EchoFool Posted August 14, 2010 Author Share Posted August 14, 2010 Good question i just been googling and taking snippets here and there till it worked... is it sloppy design ? Im no JS pro i just look on the net and copy what does till i get it to work. Where did i go wrong ? Quote Link to comment https://forums.phpfreaks.com/topic/210278-if-this-most-efficient/#findComment-1099073 Share on other sites More sharing options...
EchoFool Posted August 14, 2010 Author Share Posted August 14, 2010 bump Quote Link to comment https://forums.phpfreaks.com/topic/210278-if-this-most-efficient/#findComment-1099345 Share on other sites More sharing options...
EchoFool Posted August 23, 2010 Author Share Posted August 23, 2010 bump again Quote Link to comment https://forums.phpfreaks.com/topic/210278-if-this-most-efficient/#findComment-1102519 Share on other sites More sharing options...
trq Posted August 23, 2010 Share Posted August 23, 2010 Locked. There isn't a specific question, your asking for opinion. obviously know one has anything nice to say. Quote Link to comment https://forums.phpfreaks.com/topic/210278-if-this-most-efficient/#findComment-1102562 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.