Jump to content

If this most efficient


EchoFool

Recommended Posts

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 );

Link to comment
https://forums.phpfreaks.com/topic/210278-if-this-most-efficient/
Share on other sites

  • 2 weeks later...

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.