2016-09-29 115 views
4

評論:我累了所有的問題&回答相關此主題。Dropzone圖像上傳錯誤顯示如何刪除錯誤

我想在Dropzone中上傳img或其他文檔後刪除彈出窗口中的HTML數據。

Dropzone上傳的文件被分配 var accept = ".png";工作正常。 見代碼Here。但圖像或其它文件上傳之後再一些HTML是顯示

enter image description here

代碼段下面的例子。

var accept = ".png"; 
 
Dropzone.autoDiscover = false; 
 

 
// Dropzone class: 
 
var myDropzone = new Dropzone("#mydropzone", { 
 
    url: "/file/post", 
 
    acceptedFiles: accept, 
 
    uploadMultiple: false, 
 
    createImageThumbnails: false, 
 
    addRemoveLinks: true, 
 
    maxFiles: 3, 
 
    maxfilesexceeded: function(file) { 
 
     this.removeAllFiles(); 
 
     this.addFile(file); 
 
    } 
 
    
 
    });
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/dropzone.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://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="clsbox-1" runat="server" > 
 
\t \t <div class="dropzone clsbox" id="mydropzone"> 
 

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

回答

3

這個錯誤是因爲你正在運行在小提琴的代碼,並懸浮窗正試圖將文件上傳到一個不存在的網址引起的。

當dropzone出現錯誤時,顯示服務器在紅色彈出窗口中收到的消息,在這種情況下,它是一個html頁面。

當您將文件上傳到有效的網址時,不會發生這種情況。

您可以像這樣更改彈出窗口中的文本。

var myDropzone = new Dropzone("#mydropzone", { 
    url: "/file/post", 
    acceptedFiles: accept, 
    uploadMultiple: false, 
    createImageThumbnails: false, 
    addRemoveLinks: true, 
    maxFiles: 3, 
    maxfilesexceeded: function(file) { 
    this.removeAllFiles(); 
    this.addFile(file); 
    }, 
    init: function() { 
    this.on('error', function(file, errorMessage) { 
     if (errorMessage.indexOf('Error 404') !== -1) { 
     var errorDisplay = document.querySelectorAll('[data-dz-errormessage]'); 
     errorDisplay[errorDisplay.length - 1].innerHTML = 'Error 404: The upload page was not found on the server'; 
     } 
    }); 
    } 
}); 

或者當您處於小提琴狀態時,您可以通過僅更改課程來假裝上傳成功。

init: function() { 
    this.on('error', function(file, errorMessage) { 
    if (file.accepted) { 
     var mypreview = document.getElementsByClassName('dz-error'); 
     mypreview = mypreview[mypreview.length - 1]; 
     mypreview.classList.toggle('dz-error'); 
     mypreview.classList.toggle('dz-success'); 
    } 
    }); 
} 
+0

thak you for you。但我設置你的代碼在我的小提琴錯誤刪除,但所有錯誤刪除..如果你可以上傳錯誤的文檔,然後不彈出。所以我想彈出允許但刪除成功上傳文件,然後刪除錯誤。沒有錯誤的文件上傳..看到我的小提琴上傳任何'pdf文件,然後不彈出.https://jsfiddle.net/patelsumit5192/mxxa0bk8/8/ –

+0

@Sumitpatel剛剛更新了答案,只刪除接受的文件上的錯誤。我的建議是,如果你需要開發中繼服務器的響應,你可能想從jsfiddle切換到可以提供響應的東西,比如實際的服務器。看看「plunker」或「code.runnable」都是免費的,如果你想在網上做,也可以考慮建立你自己的環境。 – wallek876

+0

謝謝..你的代碼工作正常... –