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'];
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3