1
I’m trying to send a POST
Angular way, the same way I did in the JQuery
, however, when trying to capture the data via variable $_POST
, is not bringing any value.
I’m running a code similar to that on angular:
$http.post('/users/ajax-create', user).then(...);
The angler seems to be sending the data without the required formatting for PHP to process the parameters for the variable $_POST
.
I can only get the values if I do so:
json_decode(file_get_contents('php://input'), true);
But the above behavior is not desired. I would like to use the Angularjs in my php application, but I wouldn’t want to rewrite it or start doing different things just because of this particularity of angular.
Is there any way to send the data of a javascript object through angular, but as form parameters form-url-encoded
?
Note: If this is standard angular behavior, I wouldn’t want to keep writing any code to every project I implement angular. So if there is any library ready to convert the data to form-url-encoded
, I will be satisfied if there is an indication.
I know this may not be common in Angular, but in the case of forms with
arrays
, this function will not work properly.– Wallace Maxters
Is that right? I took a test here at the function
encodeURIComponent
with a value of the typea[b]
and he converts toa%5Bb%5D
, which is the right way to send arrays via form data.– Rodrigo Rigotti
It makes sense its placement. In fact, the function just doesn’t do the same thing as
$.param
jQuery do. If you want to add it as a reference in the reply, it will also be cool– Wallace Maxters