I am trying to perform this AJAX post but for some reason I am getting a server 500 error. I can't see any error in the python code. So the problem seems to be on the callback. I am posting the code that I am using presently. Anyone?
Html form part is the front end html part how the form is written
<form method="post" id="uploadform" onsubmit="formupload()" enctype="multipart/form-data">
<div class="form-group">
<input type="file" id="exampleInputFile" name="file">
</div>
<div class="form-group ">
<button type="submit" class="btn btn-primary pull-right" id="upload_button">Upload File</button>
</div>
</form>
Th AJAX call is made to the python code and alerts 'upload fail':
function formupload(){
event.preventDefault();
$.ajax({
url: '/uploadEmpData',
type: 'POST',
data: $('#uploadform').serialize(),
dataType: 'json',
success: function(data){
alert(data);
alert('file uploaded successfully');
},
error: function(data){
alert('upload fail');
//console.log(error);
}
});
}
The python bottle part where the function is created and data is being received from AJAX request:
def uploadEmpData():
data = request.files.get('file')
data.save('files/',overwrite=True)
if data and data.file:
return json_dumps("File uploaded successfully")
return json_dumps({'error':'Permission Denied.'})