Manipulating / Treating Dropzone return in Javascript

Asked

Viewed 596 times

1

I need to know how to manipulate server return to show that the uploaded file was not saved!

The server return object:

public class JsonReturn
{
    public bool Ok { get; set; }
    public int LinhasAfetadas { get; set; }
    public string Mensagem { get; set; }
    public string Log { get; set; }
    public object Dados { get; set; }
    public int Id { get; set; }

}

Below Follow the call of the Dropzone:

<script type="javascript">
        Dropzone.options.dropzoneForm = {
            dictDefaultMessage: "Arraste os recibos até aqui, ou clique para selecionar!",
            dictInvalidFileType: "ERRO: Tipo de arquivo não permitido!",
            acceptedFiles: "application/pdf",                
            success: function() { /* COMO DEVO TRATAR O RETORNO FAZENDO QUE SEJA EXIBIDO O "X" E O ERRO PERSONALIZADO ?*/},
        };
</script>
  • 2

    Start by also publishing what you have already tried (relevant code), also saying the problem that occurs, and what you expect sff. Welcome to Stack Overflow PT

  • Jewel... Thank you!

1 answer

0

found the answer in this post in English: Reply in English

success: function(file, response){
    if(response.code == 501){ // succeeded
        return file.previewElement.classList.add("dz-success"); // from source
    }else if (response.code == 403){  //  error
        // below is from the source code too
        var node, _i, _len, _ref, _results;
        var message = response.msg // modify it to your error message
        file.previewElement.classList.add("dz-error");
        _ref = file.previewElement.querySelectorAll("[data-dz-errormessage]");
        _results = [];
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
            node = _ref[_i];
        _results.push(node.textContent = message);
        }
    return _results;
    }
}

Good to all!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.