dsfdfd1211 2014-12-15 06:36
浏览 43
已采纳

使用ajax上传器删除上传的图像

I used ajax loader to uplaods files to server.It works fine but now i want to set delete option with each image and can delete that image before saving.My current images look like :

enter image description here

I am using this file uploader script for file uploading.Link

My Code for files upload is :

jQuery("#fileuploader").uploadFile({
    url:"<?php echo $this->getUrl('pmembers/priority/productimages/') ?>",
    multiple:true,
    fileName:"myfile",
    onSuccess: function (files, response, xhr,pd) { 
      var dir = '<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."mkd/uploads/".Mage::getSingleton("customer/session")->getId()."/"; ?>';

        jQuery('#files').append('<li style="width:60px; float:left;margin-left:5px; margin-right:5px;"><img width="60" height="60" src="'+dir+files+'" /></li><img src="cross.png" />');


       },
    });
});
  • 写回答

1条回答 默认 最新

  • dongzai3139 2014-12-15 07:57
    关注

    Try: Event when click remove button will send a request to server unlink (path: "dir+files"), after complete server will return client a notify.

    jQuery:

    var removeButton = $("li > img:last");
    removeButton.click(function(){
        if (removeButton.attr('handling') != "true") {
            removeButton.attr('handling', 'true');
            var path = removeButton.prev('img[src]').attr('src');
            $.ajax({
                type: "POST",
                dataType: "json",
                url: (url),
                data: {'path': path},
                error: function () {
                    //. Action when error.
                },
                success: function (data) {
                    //. Action when success.
                }
            }).done(function(){
                removeButton.attr('handling', 'false');
            });
        }
    });
    

    PHP:

    $path = $_POST['path'];
    $unlink = unlink($path);
    if (!$unlink) {
        print json_encode(array("return" => false)); exit();
    }else {
        print json_encode(array("return" => true)); exit();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题