Completely new to php/ajax. Every tutorial seems to be outdated in one way or another. Spent about 30 hours already trying to come up with a simple insert/retrieve script. Please help! Once i see the code working its alot easier for me to fiddle with it understand the documentation.
Im getting the following error.
[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.
My index.php relevant data, the error is on the xmlhttp.open
line.
disp_data();
function disp_data(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "update.php?status=disp",false);
This is my update.php relevant code. On the tutorial, it is supposed to load my data upon refresh, but its blank. I'm not sure why the tutorial sets it to false, when the documentation ive read at w3schools seems I should make it true, but neither work.
$status = $_GET["status"];
if ($status == "disp") {
$link = mysqli_connect("localhost", "root", "");
mysqli_select_db($link, "checkbox");
$res = mysqli_query($link, "SELECT * FROM table1");
my full index.php
<div id ="disp_data"></div>
<script src="jquery-3.2.1.min.js"></script>
<script type ="text/javascript">
(function() {
var newXHR = null;
function sendXHR(type, url, data, callback) {
newXHR = new XMLHttpRequest() || new window.ActiveXObject("Microsoft.XMLHTTP");
newXHR.open(type, url, true); // Use async = true to avoid bad user experience for waiting a Sychronous request that might block the UI.
newXHR.send(data);
newXHR.onreadystatechange = function() {
if (this.status === 200 && this.readyState === 4) {
callback(this.response); // Callback function to process the response.
}
};
}
sendXHR("GET", "update.php?status=disp", null, function(response) {
document.getElementById("disp_data").innerHTML=newXHR.responseText;
});
})();
</script>
</body>
my full update.php file
$status = $_GET["status"];
if($status=="disp")
{
$link = mysqli_connect("localhost", "root", "");
mysqli_select_db($link,"checkbox");
$res = mysqli_query($link,"SELECT * FROM table1");
echo "<table>";
while($row = mysqli_fetch_array($res))
{
echo "<tr>";
echo "<td>"; echo $row["id"]; echo "</td>";
echo "<td>"; echo $row["name"]; echo "</td>";
echo "<td>"; echo $row["city"]; echo "</td>";
echo "</tr>";
}
echo "</table>";
}