Fix home page upload to use json api instead of seperate upload code

This commit is contained in:
Tom Bloor 2017-04-21 23:38:12 +01:00
parent 00b0687136
commit a097db2017
6 changed files with 27 additions and 115 deletions

View file

@ -4,14 +4,29 @@ $(function() {
event.stopPropagation();
// Create new form data object with the contents of this form
var formData = new FormData(this);
var formData = new FormData();
formData.append('file', $('#tran-file')[0].files[0]);
formData.append('json', JSON.stringify({
transaction_type: $('#tran-type').val(),
organisation_name: $('#org-name').val(),
street_name: $('#org-street').val(),
town: $('#org-town').val(),
postcode: $('#org-postcode').val(),
transaction_value: $('#tran-value').val()
}));
$.ajax({
url: $(this).attr("action"),
type: 'POST',
data: formData,
success: function(data) {
alert(data);
console.log(data);
alert(data.message);
$('form#receipt-form')[0].reset();
},
error: function(data) {
console.log(data);
alert(data.responseJSON.message);
},
cache: false,
contentType: false,