doumengjing1500 2014-11-26 20:13
浏览 46
已采纳

用ajax删除sql表数据

i have stored image data in a sql table when uploading images. then i want to delete individual images with ajax.

here is my php code to retrieve images from table. there are few images.

while($infoi= mysqli_fetch_array($ri, MYSQLI_ASSOC)){

    $imageId= $infoi['image_id'];
    $albumIdi= $infoi['album_id'];
    $imageName= $infoi['image_name'];
    $size= $infoi['size'];
    $type= $infoi['type'];
    $mainImage= $infoi['main_image_file_path'];
    $thumbImage= $infoi['thumb_image_file_path'];
    $addedDayi= $infoi['added_day'];


    echo '  <tr class="'.$imageId.'">
            <td> <a href="'.$mainImage.'" data-lightbox="'.$albumIdi.'">   <img src="'.$thumbImage.'" class="img-responsive thumbnail"  />    </a></td>
            <td> '.$imageName.' </td>
            <td> '.$size.' Kb  </td>
            <td>'.$addedDayi.'</td>
            <td> 
                <input type="submit" class=" btn btn-sm btn-danger ico-windows" id="'.$imageId.'" value="Delete"/>

                <div class="showResult" id="'.$imageId.'" style="display:none"> this division hided </div>
            </td> 
        </tr>
          ';  
    }// inner while

how i pass the image id via ajax to the php script? in php i can use query string to pass the imageId but in ajax i have no idea to how to it.

if deleted successfully whole table row should be hided and if not deleted an error message should be showed in div class="showResult"

  • 写回答

1条回答 默认 最新

  • doubi4814 2014-11-26 20:26
    关注

    You can send it as a get query too. You just need to append the id to your url

    var url = url + "?imageId=" + id;
    

    if you use jQuery it's very simple.

    $("#select inputs").click(function() {
        var id = $(this).attr("id");
        $.ajax({
            url : "http://my.website.com/ajax-delete.php?imageId=" + id,
            success : function() {
                $("#" + id).hide();
            }
        });
    }
    

    I forget the confirm part. With jQuery you can add a callback function who can hide the element if the query succeed. I edited to add a closure.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探