1

The problem is that angularjs sends post data as json. There are several solutions:

Serverside: Angularjs - Form Post Data Not Posted?

Clientside: http://sebgoo.blogspot.de/2013/05/angularjs-post-data-to-php.html More fancy one?: http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/

I want to use the server side one:

PHP file:

<?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) {

....

My Header: The data customerFirstName is sent

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

And the Response:

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

Conclusion: Not working. Also the server side solutions I didn't manage to be successful but they anyways look more complicated for me.

Community
  • 1
  • 1
Andi Giga
  • 3,744
  • 9
  • 38
  • 68

1 Answers1

0

The answer is rename params into data.

Andi Giga
  • 3,744
  • 9
  • 38
  • 68