'Delete operation does not perform in JS - PYTHON - POSTGRESS
Controller:
**@test_ref_bp.route('/cmds', methods=['GET', 'POST', 'PUT','DELETE'])
@swag_from('test_ref_doc.yml')
def testcommands():
if request.method == 'GET':
result, status = TestRefSvc.get_cli_commands()
if request.method == 'POST':
uploaded_file = request.files['file']
if uploaded_file.filename != '':
uploaded_file.save(uploaded_file.filename)
result, status = TestRefSvc.import_cli_commands(uploaded_file.filename)
else:
result, status = [], 404
if request.method == 'PUT':
result, status = TestRefSvc.update_cli_commands(request.get_json())
if request.method == 'DELETE':
result, status = TestRefSvc.delete_cli_commands(request.get_json())
return make_response(jsonify(result), status)**
Service:
**def delete_cli_commands(cli_commands_obj):
commands_rs = TblCliCmds.query.get(cli_commands_obj['id'])
print('The Delete query is ::: ',commands_rs)
if not commands_rs:
return {'error': 'Resource not found'}, 404
db.session.delete(commands_rs)
db.session.commit()
return {'success': 'Resource deleted successfully'}, 204**
Controller.js:
**$scope.deleteCommandsData = function() {
var dataset = {
"id":$scope.loadCommandsData
}
console.log(dataset);
alert(dataset.id);
var api_url = $rootScope.base_url + $scope.app_route + "/cmds";
var config = {
headers : {
'Content-Type': 'application/json'
}
}
$http.delete(api_url, dataset, config)
.then(function (status) {
alert('Deleted successfully');
});
}**
By calling delete operation, I have received the CORS origin error and tried all the possible ways to figure it out the issues. Is there any mistakes in the controller or JS or service layer.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
