When submitting an AngularJS form using $http.post(), variables received by the PHP script may appear as undefined, despite receiving a 200 OK response.
By default, AngularJS sets the Content-Type header to application/json for HTTP POST requests. However, if a form-encoded payload is sent instead of JSON data, PHP will not populate the $_POST array as expected.
There are two primary solutions:
Use the Default JSON Header:
Send Form-Encoded Data:
For the second solution:
$query_string = file_get_contents("php://input"); parse_str($query_string, $data); $email = $data['email']; $password = $data['password'];
The above is the detailed content of Why are my AngularJS $http.post() variables undefined in my PHP script?. For more information, please follow other related articles on the PHP Chinese website!