Home > Article > Backend Development > How to Retrieve Request Payload in PHP from Ajax Store Operations?
Retrieve Request Payload in PHP
In an application using PHP, ExtJS, and Ajax store, it was observed that data transmitted during create, update, and destroy operations is not found in either $_POST or $_GET. Instead, the Chrome Console reveals the outgoing parameters in JSON format within the "Request Payload" field.
To retrieve this data in PHP, utilize the following snippet:
$request_body = file_get_contents('php://input');
If the payload is in JSON format, decode it with:
$data = json_decode($request_body);
This assigns the decoded JSON data to the $data variable, making it accessible as a PHP array.
"php://input" is a read-only stream that efficiently retrieves data from the request body, irrespective of enctype values. It is preferred over "$HTTP_RAW_POST_DATA" due to its reliability and memory efficiency.
The above is the detailed content of How to Retrieve Request Payload in PHP from Ajax Store Operations?. For more information, please follow other related articles on the PHP Chinese website!