I want to pass data from angularjs to wordpress using AJAX
In my angular code i have this data:
$scope.registrations.push({ id_associate: '1', activity:'demo1', qty:"1" });
$scope.registrations.push({ id_associate: '2', activity:'demo2', qty:"15" });
$scope.registrations.push({ id_associate: '3', activity:'demo3', qty:"5" });
And then i call an AJAX method in this way:
$http({
method : 'POST',
url: '/wp-admin/admin-ajax.php',
params: {
action: 'registration',
fn: 'registerUsers',
registrations: $scope.registrations, //???????
}
}).success(function(data) {
console.log( 'sucess data' );
});
Then in WordPress i have the function for using the data:
function registration_ajax() {
global $current_user;
get_currentuserinfo();
switch ( $_REQUEST['fn'] ) {
case 'registerUsers':
$registrations = ?????;
foreach ( $registrations as $reg ){
self::saveRegistration(
$reg->id_associate,
$reg->activity,
$reg->qty,
$current_user->ID
);
}
break;
}
}
But I don't know how to pass the data from angularjs and then receive the data in the Wordpress side.
How should I pass the data?