Javascript Dropzone JS抛出;“未定义”;在加入“;错误事件“;

Javascript Dropzone JS抛出;“未定义”;在加入“;错误事件“;,javascript,php,html,dropzone.js,Javascript,Php,Html,Dropzone.js,我的Dropzone限制为2个文件(maxFiles:2)。如果用户将新文件拖动到Dropzone,MaxFileOverses事件将显示错误 myDropzone.on("maxfilesexceeded", function(file){ alert("no more files accepted"); myDropzone.removeFile(file); }) 但是: 如果我添加“错误事件” 要在某个操作失败时获得响应,Dropzone会发出“

我的Dropzone限制为2个文件(maxFiles:2)。如果用户将新文件拖动到Dropzone,MaxFileOverses事件将显示错误

myDropzone.on("maxfilesexceeded", function(file){
        alert("no more files accepted");
        myDropzone.removeFile(file);
    })
但是: 如果我添加“错误事件”

要在某个操作失败时获得响应,Dropzone会发出“未定义”警报。 错误事件上的参数应正确。。 Qoute(DropzoneJS主页):

错误:发生错误。将errorMessage作为第二个参数接收,如果错误是由XMLHttpRequest引起的,则将xhr对象作为第三个参数接收

因此,第一个参数是文件,第二个是错误消息(根据作者),第三个参数是来自服务器的错误

服务器上的错误响应如下所示:

$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会给我一个“未定义的”?

第三个参数是一个
XHR
对象,而不是响应。请试试这个:

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

谢谢你的快速回答!现在可以了。我想只要通过json对象就足够了,不客气!如果这解决了问题,请将其标记为已接受(以便将来面临相同问题的人能够轻松发现)。
myDropzone.on("error", function(file, errormessage, xhr){
    if(xhr) {
        var response = JSON.parse(xhr.responseText);
        alert(response.message);
    }
});