Attempt at fixing file upload

master
Davide Bongiovanni 8 years ago
parent 6214390df4
commit 0e22e55310

@ -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 = '<p id="datasheet-info"><i class="fa fa-check"></i></p>';
$('#datasheet-info').replaceWith(datasheet_par);
},
// Custom XMLHttpRequest
xhr: function() {
var xhr = $.ajaxSettings.xhr();
xhr.upload.onload = function(){
var datasheet_par = '<p id="datasheet-info"><i class="fa fa-check"></i></p>';
$('#datasheet-info').replaceWith(datasheet_par);
} ;
return xhr;
},
});

@ -68,7 +68,7 @@
<div class="details-content"><p id="datasheet-info"></p></div>
</div>
<div class="round-button"><a href="#" id="edit_button"><i class="fa fa-pencil" aria-hidden="true"></i></a></div>
<div class="round-button"><a href="#" id="edit-button"><i class="fa fa-pencil" aria-hidden="true"></i></a></div>
<div class="small-square-button"><a href="#" onclick="overlay_out()"><i class="fa fa-times" aria-hidden="true"></i></a></div>
<!--<h2 class="card-id"></h2>
<input type="text" name="name" placeholder="Name" id="name"><br><br>

Loading…
Cancel
Save