[英]Angular's $http.post to PHP empty $_POST
我有以下情况,我有一个名为contact
的Angular变量,它是一个具有以下成员的JSON对象:
我console.log(contact)
并记录了正确的信息,但是一旦发送, $_POST['contact']
导致一个空数组。 我正在阅读,发现$_POST['contact']
不会像是jQuery的http请求那样被填充。 所以我将其固定为以下内容:
$params = json_decode(file_get_contents('php://input'),true);
print_r($params);
这是Angular函数:
$scope.submitForm = function(contact){
console.log(contact);
$scope.clearContactFormData();
return $http.post('http://localhost/cpr_courses/app/methods/contact.php', contact).success(function(data){
Materialize.toast(data, 4000);
});
}
仍然print_r($params)
为空。 我不知道还有什么事。 有什么帮助吗?
编辑
console.log()
输出以下内容:
Array[0]
email
:
"asd@asd.asd"
length
:
0
message
:
"rubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOBrubAWREIUVBAERWOBNATEIOB"
name
:
"rubAWREIUVBAERWOBNATEIOB"
phone
:
"13345678"
这是网络标签图片:
这是JSON对象的声明:
$scope.contact = {};
$scope.onlyNumbers = /^[0-9]+$/;
稍后将其放在这样的表单上:
<form method="post" class="form-sl" role="form" name="contactForm" ng-submit="submitForm(contact)" novalidate enctype="multipart/form-data">
之后,在每个字段上都这样:
<input type="email" name="email" id="email" ng-model="contact.email" autocomplete="off" ng-maxlength="50" length="50" required/>
这样可以吗?
$_POST
超全局变量是一种PHP商品,用于自动解码HTML表单发送的典型POST请求的正文。 换句话说,它期望Content-Type
请求标头中的这些值之一:
application/x-www-form-urlencoded
multipart/form-data
由于您具有application/json
,因此它保持为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.