Home How to access post data from Angular / Ionic to PHP
Reply: 1

How to access post data from Angular / Ionic to PHP

Bernie K.
1#
Bernie K. Published in 2018-01-12 15:20:51Z

I'm posting JSON data from Angular / Ionic to PHP, but I'm having trouble accessing the data from PHP.

Here is my php code:

$jsonData = file_get_contents('php://input');
$data = json_decode($jsonData, true);

I saved the $jsonData in the database to see what the data looks like and it looks like this:

{"headers":null,"params":{"event_title":"My Event","event_start_date":"2018-01-12","event_end_date":"2018-01-12","post_type":"add"}}

When I save the json_decode Associative Array to the database, it just saves it as "Array", so I cannot see what the Array looks like. So I echo the data (as response) to Angular and here is what the $data looks like in my browser's console HttpErrorResponse:

"Array↵(↵    [headers] => ↵    
[params] => Array↵  …1-12↵            [post_type] => add↵        )↵↵)↵"

There are a few posted data missing from the above response array such as event_title. Maybe the full posted data is there and displayed as "…1-12".

I appreciate any help on this:

  1. What am I doing wrong in getting the JSON data to Array in PHP code above?
  2. How do I access the data such as "event_title" in my PHP code?
Arun Kumaresh
2#
Arun Kumaresh Reply to 2018-01-12 15:37:50Z

you can get event_title by

print_r($data['params']['event_title']);
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.297922 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO