I'm doing a simple blog with Angular + Django. I have a page when the user can create a new post, writing the title and the body. In addition, at the end, he can add a file.
This is the controller:
$scope.newPost = {};
$scope.addPost = function(){
if ($scope.newPost){
PostListSrv.addPost.add($scope.newPost, function(data) {
if (data) {
console.log('success');
}
}, function(error) {
if (error) {
console.log('error');
}
}
);
} else {
console.log('Error');
}
};
This is the service where I call the server:
.....
addPost: $resource('my_url', {
}, {
add: {
method: 'POST',
headers: { 'Content-Type': 'multipart/form-data' },
params:{title:'title', text:'text', file: 'file'}
}
}),
....
The problem is that if I try to add a new post, I get a 400 Error. In particular in the 'response' tab on 'Network' (Firefox) I have a red line that writes: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data. How can I do?