diff --git a/static/script.js b/static/script.js index d34e54b..567e1ab 100644 --- a/static/script.js +++ b/static/script.js @@ -94,41 +94,37 @@ function save(partID) { partnos = partno_v.split(' '); - if (datasheet.length == 0) { - datasheet = []; - datasheet[0] = ''; - } + var data = new FormData(); + + if (datasheet.length == 1) + data.append('datasheet-file', datasheet[0]); + data.append('block', block_v); + data.append('partno', partnos[0]); + if (partnos.length > 1) + data.append('partnoalt', partnos[1]); + if(partnos.length > 2) + data.append('partnoalt2', partnos[2]); + data.append('description', description_v); + data.append('quantity', quantity_v); + data.append('notes', notes_v); + $.ajax({ // Your server script to process the upload url: 'https://www.elab.kth.se/parts/alter/' + partID, type: 'POST', - data: { - file: datasheet[0], - block: block_v, - partno: partnos[0], - partnoalt: partnos[1], - partnoalt2: partnos[2], - description: description_v, - quantity: quantity_v, - notes: notes_v - }, + data: data, // Tell jQuery not to process data or worry about content-type // You *must* include these options! cache: false, contentType: false, processData: false, + success: function(data) { + var datasheet_par = '

'; + $('#datasheet-info').replaceWith(datasheet_par); + }, - // Custom XMLHttpRequest - xhr: function() { - var xhr = $.ajaxSettings.xhr(); - xhr.upload.onload = function(){ - var datasheet_par = '

'; - $('#datasheet-info').replaceWith(datasheet_par); - } ; - return xhr; - }, }); diff --git a/templates/partsearch.html b/templates/partsearch.html index ee6a4c0..89fba24 100644 --- a/templates/partsearch.html +++ b/templates/partsearch.html @@ -68,7 +68,7 @@

-
+