php - about using ajax -



php - about using ajax -

i'm displaying cotntent of text file on web page(say between <div id='text'></text>) file's content edited user view page, utilize ajax write file , display current user, if there users browsing page @ same moment have refreh page see new edited content. want know how utilize ajax create part contain file content remain updated continmuosly without refreshing page

<script type='text/javascript'> function change(){ if (window.xmlhttprequest) xhr=new xmlhttprequest(); else xhr=new activexobject("microsoft.xmlhttp"); //ie5 xhr.onreadystatechange=function() { if (xhr.readystate==4 && xhr.status==200) { if(xhr.responsetext=="empty") return; document.getelementbyid("space").innerhtml=xhr.responsetext; } } var str=document.getelementbyid('msg').value; document.getelementbyid("msg").value=""; xhr.open("get","response.php?q="+str,true); xhr.send(); } </script> <center> <div id='space'>nothing</div> <input type='text' name='msg' id='msg'> <input type='button' onclick='change()' value='click'> </center>

the simplest way accomplish "server push" effect through polling.

in case, can add together functionality adding simple javascript statement:

window.onload = function() { setinterval("change();", 5000); };

this code phone call change(); every 5000 ms.

php ajax

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -