javascript - two set interval function in single PHP file is not working -
function updatechatajax1() { var ajaxrequest; // variable makes ajax possible! ajaxrequest = new xmlhttprequest(); // create function receive data sent server ajaxrequest.onreadystatechange = function(){ if(ajaxrequest.readystate == 4){ //the response document.getelementbyid('content1').innerhtml = ajaxrequest.responsetext; } } ajaxrequest.open("get", "open_ajax.php?mode=ref", true); ajaxrequest.send(null); } $(function(){ setinterval(function () { updatechatajax1(); // javascript function request ajax file. }, 2000); }); $(function(){ setinterval(function () { updatechatajax(); // javascript function request ajax file. }, 2000); });
when page loaded both functions updatechatajax() , updatechatajax1() working together. want call 1 function @ time of time interval.
when loading execute both operations together.
updatechatajax(); updatechatajax1();
then setinterval both actions
var flag=0; $(function(){ setinterval(function () { if(flag==0) { updatechatajax(); } else { updatechatajax1(); } }, 2000); });
change flag choose operation.
flag=0 -> updatechatajax();
and
flag=1 -> updatechatajax1();
Comments
Post a Comment