0
我想在服务器返回错误时从dropzone.js触发javascript警报。 (在json中)。如何使用Dropzone.js在服务器错误响应后触发警报
这是我的功能/方法。它似乎工作正常。
public function file_upload($account_id,$bid_id) {
$path = FMREPO . "/account-" . $account_id . "/bid-project-" .$bid_id . "/";
if (file_exists ($path)){
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$fileName = $_FILES['file']['name'];
$targetPath = $path . "diagram-" . $bid_id . "-";
$targetFile = $targetPath . $fileName ;
move_uploaded_file($tempFile, $targetFile);
// $this->load->database(); // load database
// $this->db->insert('file_table',array('file_name' => $fileName));
}
} else{
header('HTTP/1.1 500 Internal Server Directory Not Found');
header('Content-Type: application/json; charset=UTF-8');
die(json_encode(array('error' => 'File Could Not Be Saved')));
}
}
这是我的Dropzone选项。这是我不知道如何去做或者让它工作的部分。 “错误:”是我添加的,但它总是触发警报,即使文件上传成功。我需要在这里做什么?
Dropzone.options.diagramDropzone = {
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 6, // MB
maxFiles: 2,
thumbnailWidth: 100,
thumbnailHeight: 100,
error: function(){
alert('error');
},
init: function() {
this.on("maxfilesexceeded", function(file){
alert("No more files please!");
console.log(file);
this.removeFile(file);
});
}
}
编辑:我刚刚意识到这个
error: function(){ //alert here },
应该
error: function(response){ //alert here },
所以现在正在努力!但与alert(response)
我得到[对象]。所以现在的问题是如何提醒我的字符串?
这有助于....谢谢 –