Send text along with FormData Ajax file

0

I'm doing a test with the script below, for file upload:

function uploadFile(){
    var file = _("file1").files[0];
    // alert(file.name+" | "+file.size+" | "+file.type);
    var formdata = new FormData();
    formdata.append("file1", file);
    var ajax = new XMLHttpRequest();
    ajax.upload.addEventListener("progress", progressHandler, false);
    ajax.addEventListener("load", completeHandler, false);
    ajax.addEventListener("error", errorHandler, false);
    ajax.addEventListener("abort", abortHandler, false);
    ajax.open("POST", "file_upload_parser.php");
    ajax.send(formdata);
}

What happens is that in addition to the file itself, I need to send 3 more text fields. I've tried a field like this:

var teste = $('input:text[name=teste]').val();
formdata.append("teste", teste);

But the following error occurs:

How can I do to send these variables? And in arquivo file_upload_parser.php how can I receive these variables?

    
asked by anonymous 28.11.2016 / 13:06

0 answers