How to refresh php+ajax in real time
This article will explain in detail how to refresh php+ajax in real time. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
The details are as follows:
Ajax automatic refresh seems to be a very common problem, and it was also stuck to do a web chat room program before. After a period of study, I finally made a code framework that can automatically refresh the web page. I hope that my lost relatives will not take so many detours like me.
Html section:
Function loadXMLDoc () / / ajax sends the request and displays {var xmlhttp; if (window.XMLHttpRequest) {/ / code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest ();} else {/ / code for IE6, IE5 xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");} xmlhttp.onreadystatechange=function () {if (xmlhttp.readyState==4 & & xmlhttp.status==200) {document.getElementById ("myDiv") [xss_clean] = xmlhttp.responseText;} xmlhttp.open ("POST", "/ chat.php", true) Xmlhttp.send (); setTimeout ("loadXMLDoc ()", 1000); / / Recursive call} loadXMLDoc (); / / execute first