【问题标题】:Angularjs Post Php, issues with reading $_Post data after reading some solutionsAngularjs Post Php,阅读一些解决方案后读取 $_Post 数据的问题
【发布时间】:2014-06-24 08:38:13
【问题描述】:

问题是 angularjs 以 json 格式发送帖子数据。有几种解决方案:

服务器端: 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

结论:不工作。还有服务器端解决方案我没能成功,但它们对我来说看起来更复杂。

【问题讨论】:

    标签: php angularjs post


    【解决方案1】:

    答案是将参数重命名为数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-23
      • 2015-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      相关资源
      最近更新 更多