how to get jQuery Ajax refresh while loop when database gets updated

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



how to get jQuery Ajax refresh while loop when database gets updated



I have colored button gets changed based on database value, when this value updated I want to also update the button color at same time, but my current code not dynamic enough to change the button when click on it


<?php
$conn = new mysqli('localhost', 'root', '123456', 'lc');
$sql = "SELECT * FROM lc where customer='souhail'";
$result = $conn->query($sql);
// while ( $row=mysqli_fetch_assoc($result)) {

while($row = $result->fetch_array()) {
echo '<div class="container">';
echo 'LC ID :<input type="text" class="fname" value="'.$row['element_6'].'"><br>';
echo 'Status :<input type="text" class="lname" value="'.$row['element_101'].'"><br>';
$recordId = $row['lc_id'];
echo '<input class="recordId" name="recordId" value="' . $recordId . '">';


?>


$(document).ready(function()
$(".update").on("click", function()
var $container = $(this).closest(".container");
var fname = $container.find(".fname").val();
var lname = $container.find(".lname").val();
var recordId = $container.find(".recordId").val();

$.ajax(
url:'update.php',
method:'POST',


data:
fname:fname,
lname:lname,
recordId: recordId
,
success:function(response)

alert(response);

,

error: function(xhr, textStatus, error)
alert(xhr.statusText);
console.log(textStatus);
console.log(error);


);
);
);





Holy indents batman! Can you help us by formatting your code? The better your code looks, the easier it is to help you.
– FrankerZ
Aug 12 at 20:53










By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard