My ajax succes event handler is not getting called.
I use backbone as my clientside MVC This is how i set my ajax function:
$.ajax({
type: "POST"
, url: "/image-delete"
, data: { "imageName" : "someImage.jpg" }
, success: function(response) {
console.log("succes = ", response);
self.model.get('pictures').splice(imageName, 1);
$(event.currentTarget).closest('.picture-frame').remove();
console.log(self.model);
}
, error: function(response) {
utils.showAlert('Error', 'An error occurred while deleting this picture', 'alert-error');
}
And this is the serverside with node.js/express:
exports.deleteImage = function(req, res) {
console.log("Deleting image ", req.body.imageName);
var filePath = "./private/uploads/" + req.body.imageName;
fs.unlink(filePath, function(err) {
if(err){
console.log("error with deleting:", err);
} else {
console.log("succesfull deleted");
res.set({'Content-Type': 'text/plain'});
res.send("succesfull deleted");
res.end();
}
});
}
The file is succesfull deleted and in my terminal i get the message "succesfull deleted" so the "else" function in node is fired, but the succes of the ajax function is nog called...
obsolete
I believe
successhould be calledsuccess, in case you copy-and-pasted this here.