I'm currently working on a blog project using Angular and Django. I have created a page where users can create new posts by entering a title, body, and attaching a file.
Below is the controller code:
$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 used to communicate with the server:
.....
addPost: $resource('my_url', {
}, {
add: {
method: 'POST',
headers: { 'Content-Type': 'multipart/form-data' },
params:{title:'title', text:'text', file: 'file'}
}
}),
....
The issue arises when attempting to add a new post, resulting in a 400 Error. Specifically, in the 'response' tab under 'Network' (Firefox), a red line indicates: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data. How can this be resolved?