2016-11-13 23 views
1

我正在製作一個網絡聊天應用程序,它具有拖放文件並將其上傳到服務器的功能(我必須讓它像擁有此功能的whatsapp網頁一樣)。我使用dropzone.js來實現這一點,迄今爲止除了一件事以外一直工作得很好。從瀏覽器中刪除圖像時,事件'發送'從未被調用。 這裏的例子使用dropzone.js從瀏覽器中刪除圖像

new Dropzone('.drag-overlay', { 
    url: "www.example.com", 
    paramName: "attachment", 
    init: function() { 
    this.on("drop", function(e){ 
     console.log("Drop event"); 
    }); 
    this.on("sending", function(file){ 
     console.log("Sending event"); 
    }); 
    } 
}); 

跌落事件被稱爲罰款,但從來沒有送被調用。任何人都可以給我一個方向如何使用這個庫從另一個瀏覽器發送文件?

謝謝

回答

0

發送事件呼叫。上傳任何文件。更改呼叫Dropzone方法。

var myDropzone = new Dropzone 

現場演示Here。看到控制檯網絡

看下面的例子

// Dropzone class: 
 
var myDropzone = new Dropzone(".drag-overlay", { 
 
    url: "www.example.com", 
 
    paramName: "attachment", 
 
    init: function() { 
 
    this.on("drop", function(e){ 
 
    alert('Drop event'); 
 
    console.log("Drop event"); 
 
    }); 
 
    this.on("sending", function(file){ 
 
    alert('sending event'); 
 
    console.log("Sending event"); 
 
    
 
}); 
 
/*This Code Only Remove tooltip error*/ 
 
this.on('error', function(file, errorMessage) { 
 
    var mypreview = document.getElementsByClassName('dz-error'); 
 
    mypreview = mypreview[mypreview.length - 1]; 
 
    mypreview.classList.toggle('dz-error'); 
 
    mypreview.classList.toggle('dz-success'); 
 
}); 
 
    } 
 
    
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/dropzone.css" rel="stylesheet"/> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/basic.css" rel="stylesheet"/> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/dropzone.js"></script> 
 
<div class="clsbox-1" runat="server" > 
 
\t \t <div class="dropzone drag-overlay" id="drag-overlay"> 
 

 
\t \t </div> 
 
\t </div>

+0

對不起似乎在你的小提琴,發送事件仍然沒有得到當我從滴圖像開除瀏覽器。你能詳細說明你的答案嗎? – Pratansyah

+0

我認爲這裏有一個誤解,我看到了你的更新答案,並且添加了一條警告,以便更容易地找出事件是否被解僱。只是爲了清楚起見,我的意思是「從瀏覽器拖放圖像」是讓我們說,你打開另一個選項卡上的谷歌搜索圖像,從結果中拖出一個圖像,並將其放到jsFiddle中的放置區域 – Pratansyah