Script para subir archivos de manera asyncrona con Jquery ajax

Lucio Flores
2014-10-02T15:20:42Z

gistfile1.js

| $("#btn-save-file").click(function (event){
| //First, create a form object
| var formData = new FormData();
| //Second, assign the input file element to a var
| var file = document.getElementById("fileInput");
| //Third, add the input file to the form object, in this case idcard is the name of the input and file.files[0] are the bytes
| formData.append("file", file.files[0]);
| //Fourth, make the ajax request
|
| $.ajax({
| url: 'SaveDocumentacion',
| type: 'POST',
| data: formData,
| processData: false,
| beforeSend: function () { },
| success: function () {
| },
| contentType: false,
| error: function () {
| }
| }).done(function (response) {
| console.log(response);
| });
| });