I'm trying to perform an ajax request in wordpress using angularjs. After a while I managed to get it working. However, I'm not sure this is the best solution. I'm also not able to pass objects as parameters.
$scope.submitForm = function() {
$http({
method: 'POST',
url: APP.ajaxurl,
params: {
action: "form-submission",
car: $scope.car.selectedOptions.name,
extras: $scope.car.selectedOptions.extras,
},
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function(data){
console.log(data);
});
}
This works, but in my functions.php I have to use $_REQUEST instead of $_POST and if I test the code below I get an error because extras is an object.
add_action( 'wp_ajax_nopriv_form-submission', 'submit_form' );
add_action( 'wp_ajax_form-submission', 'submit_form' );
function submit_form(){
echo $_REQUEST['extras'];
wp_die();
}
Any ideas?