2016-07-14 2 views
0

My Dropzone은 2 개의 파일 (maxFiles : 2)로 제한됩니다. 사용자가 새 파일을 Dropzone으로 드래그하면 maxfileexceeds 이벤트에 오류가 표시됩니다. "오류 이벤트"를 추가 할 때 Dropzone JS에서 "undefined"가 throw됩니다.

myDropzone.on("maxfilesexceeded", function(file){ 
     alert("no more files accepted"); 
     myDropzone.removeFile(file); 
    }) 

그러나

: 내가 "오류 이벤트".. 뭔가가 실패 할 경우
myDropzone.on("error", function(file, errormessage, response){ 
     alert(response.message); 
    }) 

응답을 얻을 수를 추가하는 경우, DROPZONE는 "정의되지 않은"경고합니다. 에러 이벤트에 PARAMS가 정확해야 .. 있는 qoute (DropzoneJS 홈페이지)

error: An error occured. Receives the errorMessage as second parameter and if the error was due to the XMLHttpRequest the xhr object as third.

그래서 제 PARAM은 (저자에 의한) 파일, 둘째 ErrorMessage가 있고 3 PARAM은 오류라고 서버에서 가져옵니다.

서버의 오류 응답은 다음과 같습니다

$response = array('status' => 'error', 'message' => 'unknown error occured'); 

header('HTTP/1.1 500 Internal Server Error'); 
header('Content-type: application/json'); 
$response["message"] = $message; 
exit (json_encode($response)); 

은 왜 DROPZONE는 나에게 "정의"를 제공 하는가?

답변

0

세 번째 매개 변수는 응답이 아닌 XHR 개체입니다. 사용해보기 :

myDropzone.on("error", function(file, errormessage, xhr){ 
    if(xhr) { 
     var response = JSON.parse(xhr.responseText); 
     alert(response.message); 
    } 
}); 
+0

매우 빠른 답변에 감사드립니다. 이제 작동합니다. json 객체를 전달하는 것만으로 충분하다고 생각했습니다. – shiroxxs

+0

여러분 환영합니다! 이 방법으로 문제가 해결되면 받아 들일 수있는 것으로 표시하십시오 (앞으로 같은 문제에 직면 한 사람들도 쉽게 발견 할 수 있습니다). –

관련 문제