javascript - Dropzone JS throws "undefined" when adding "error event" - Stack Overflow

My Dropzone is limited to 2 Files ( maxFiles: 2). If the user drags a new File into the Dropzone, the m

My Dropzone is limited to 2 Files ( maxFiles: 2). If the user drags a new File into the Dropzone, the maxfileexceeds event shows an error.

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

But: If I add the "error event"..

myDropzone.on("error", function(file, errormessage, response){
        alert(response.message);
    })

to get a response if something fails, Dropzone alerts an "undefined". The params on the error event should be correct.. Qoute(DropzoneJS homepage):

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

So the first param is the file, second an errormessage (according to the author) and the 3rd param is a error which es from the server.

The error response on the server looks like this:

$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));

so why does Dropzone give me an "undefined" ?

My Dropzone is limited to 2 Files ( maxFiles: 2). If the user drags a new File into the Dropzone, the maxfileexceeds event shows an error.

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

But: If I add the "error event"..

myDropzone.on("error", function(file, errormessage, response){
        alert(response.message);
    })

to get a response if something fails, Dropzone alerts an "undefined". The params on the error event should be correct.. Qoute(DropzoneJS homepage):

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

So the first param is the file, second an errormessage (according to the author) and the 3rd param is a error which es from the server.

The error response on the server looks like this:

$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));

so why does Dropzone give me an "undefined" ?

Share Improve this question asked Jul 14, 2016 at 15:49 shiroxxsshiroxxs 511 silver badge7 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 7

The third parameter is an XHR object not the response. Please try this:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744293559a4567149.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信