I'm writing this Angular (1.6.4) service:
service.create = function(element, data) {
var deferred = $q.defer();
// -----------------------------------------------------------------------------
// -- Post element
// -----------------------------------------------------------------------------
$http({
method: 'POST',
url: '/api/' + element.toLowerCase(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: data,
transformRequest: function(obj) {
var str = [];
for (var p in obj) {
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
}
return str.join('&');
}
}).then(function infoCallback(response) {
console.log('yeah!');
deferred.resolve(response);
}, function errorCallback(response) {
console.error("[ FAILED ] >> " + response);
});
return deferred.promise;
};
Data are posted well. But I don't know why, callbacks are not called. It works well with get method.
I tried this unsuccessfully: Success Callback not called when $http post is in method scope
Thanks a lot in advance for your help.