php - Retrieve all data from database via ajax with no get or post request -
i don't know how fetch data no request, i've been googling seems request mandatory. in example want load data asynchronously. if database updated admin there's no need client refresh page.
thanks in advance.
results.php
<?php $con=mysqli_connect("host","xxx","xxx","xxx"); if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } $result = mysqli_query($con,"select * pages"); while($row = mysqli_fetch_array($result)) { echo "<a href=" . $row['url'] . ">" . $row['url'] . "</a>"; echo "<br>"; } mysqli_close($con); ?>
index.html
<html> <script> function showlinks() { if (window.xmlhttprequest) { // code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else { // code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("links_area").innerhtml=xmlhttp.responsetext; } } xmlhttp.open("get",results.php,true); xmlhttp.send(); } </script> //<body onload="showlinks()"> first try, didn't work //<button onclick="showlinks()">click</button> second try, didn't work neither <div id="links_area"><img src="loading.gif"/></div> </body> </html>
pushing data out client opposed responding request data requires open connection client maintained duration of availability of push. there various different ways achieve type of connection, 2 of more popular approaches long polling , web sockets. here's reading:
Comments
Post a Comment