更新数据库时如何在循环时获取jQuery Ajax刷新

时间:2018-08-12 20:49:27

标签: php ajax

我已经根据数据库值更改了按钮的颜色,当此值更新时,我也想同时更新按钮的颜色,但是我当前的代码不够动态,无法在单击按钮时更改按钮

<?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);
                            }

                        });
      });
    });

0 个答案:

没有答案