问题是angularjs将发布数据发送为json。有几种解决方案:
了Serverside: Angularjs - Form Post Data Not Posted?
客户方: http://sebgoo.blogspot.de/2013/05/angularjs-post-data-to-php.html 更奇特的一个?: http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/
我想使用服务器端:
PHP文件:
<?php
$data = file_get_contents("php://input");
$errors['EncodeI']=$data->customerFirstName;
$data = json_decode($data, TRUE);
$errors['EncodeII']=$data['customerFirstName'];
echo return_sql2json($errors, $rows);//just a function which returns the error messages
?>
JS: ...
$http({
url: 'read.php',
method: "POST",
// headers : {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'},
params: {
customerFirstName: $scope.customerFirstName,
customerLastName: $scope.customerLastName,
customerEmail: $scope.customerEmail
}
}).success(function(data) {
...
我的标题:发送数据customerFirstName
Remote Address:::1:80
Request URL:http://localhost/360/app/read.php?customerEmail=aa&customerFirstName=aa&customerLastName=aa
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:no-cache
Connection:keep-alive
Content-Length:0
Cookie:AccessKey=somePW; Email=someemail; PHPSESSID=somesession
Host:localhost
Origin:http://localhost
Pragma:no-cache
Referer:http://localhost/360/app/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36
Query String Parametersview sourceview URL encoded
customerEmail:aa
customerFirstName:aa
customerLastName:aa
Response Headersview source
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Length:310
Content-Type:text/html
Date:Wed, 07 May 2014 11:21:46 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=96
Pragma:no-cache
Server:Apache/2.4.9 (Win32) OpenSSL/0.9.8y PHP/5.4.27
X-Powered-By:PHP/5.4.27
响应:
errors: {EncodeI:null, EncodeII:null, customerFirstName:First Name is required,…}
EncodeI: null
EncodeII: null
customerEmail: "Email is required"
customerFirstName: "First Name is required"
customerLastName: "Last Name is required"
success: false
结论:不起作用。服务器端解决方案我也没有成功,但对我来说它们看起来更复杂。
答案 0 :(得分:0)
答案是将params重命名为数据。