Jordan
Jordan

Reputation: 307

How to pass Array with Dropzone Form Data

I am using DropZone and trying to pass Array with the formData.append() for on("sending") method. I couldnt find any example where we are passing additional data of List objects(except multiplefiles). Could you please guide me how to send multiple custom objects with formData.

I tried below but getting xss exception where "" is replaced with Quote&. I am using processqueue method and collecting object via Model on the back end but its failing with below error.

listOfNumber: {"id":2,"val":"5"}{"id":3,"val":"6"}{"id":4,"val":"8"}{"id":5,"val":"9"}{"id":6,"val":"8"}

code
: 
"Invalid input : {"id":2,"val":"5"}{"id":3,"val":"6"}{"id":4,"val":"8"}{"id":5,"val":"9"}{"id":6,"val":"8"}
: 
"listOfNumber"

My code for on Sending method:

this.on("sending", function(data, xhr, formData) {
            formData.append("Id", $("#id").val());
            formData.append("listOfNumber",getScore());
             xhr.ontimeout = (() => {
                            $.unblockUI();
              });
        });
    
function getSCore() {
let score = [];
let str = '';
let cnt = 1;
$(".score").each(function() {
    let test = {
        id:parseInt(cnt),val:$(this).val()
    };
    
    score.push(test);
    cnt++;
    str += '{"id":'+cnt+',"val":"'+$(this).val()+'"}'
});
return str;

Upvotes: 0

Views: 99

Answers (0)

Related Questions