相关文章推荐
阳刚的板凳  ·  JavaEE 使用 JQuery 完成 ...·  1 周前    · 
微醺的匕首  ·  7.2-03 ...·  11 月前    · 

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>
                <input type="submit" class=" btn btn-sm btn-danger ico-windows" id="'.$imageId.'" value="Delete"/>
                <div class="showResult" id="'.$imageId.'" style=""> this division hided </div>
    }// 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
    doubi4814
    2014-11-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.

    采纳该答案 专家已采纳 已采纳该答案
    登录 后可回复...

相关推荐 更多相似问题