Die jQuery-Ajax-Anfrage funktioniert, dieselbe AngularJS-Ajax-Anfrage nicht
Ich lerne AngularJS und versuche, ein Front-End-System zu erstellen, das Daten von Wordpress abruft.
Auf der Back-End-Seite scheint alles richtig eingerichtet zu sein, und wenn ich jQuery ajax request verwende, werden die Daten ohne Probleme abgerufen.
jQuery.ajax({
type: 'POST',
url: '/wp-admin/admin-ajax.php',
data: {
action: 'getdataajax'
},
success: function(data, textStatus, XMLHttpRequest){
console.log(data);
},
error: function(MLHttpRequest, textStatus, errorThrown){
console.log(errorThrown);
}
});
Aber wenn ich versuche, dasselbe mit AngularJS zu tun, funktioniert es nicht. Ich versuche, die Ajax-Anfrage mit folgendem Code zu replizieren:
myApp.factory('productsData', function($http, $log) {
return {
getProducts: function(successcb) {
return $http({
method: 'POST',
url: '/wp-admin/admin-ajax.php',
data: {action: 'getdataajax'}
}).success(function(data, status, headers, config) {
successcb(data);
$log.info(data, status, headers(), config)
}).error(function(data, status, headers, config) {
$log.warn(data, status, headers(), config)
});
},
};
});
Wenn ich es anmelde, gibt es 0 aus. Was fehle ich?
Danke für Ihre Hilfe.
P.S. Der Controller sieht folgendermaßen aus:
myApp.controller('ProductsController', function ProductsController($scope, productsData) {
$scope.sortorder = 'name';
// $scope.products = productsData.products;
// $scope.products = productsData.getProducts();
productsData.getProducts(function(products){
$scope.products = products;
});
});