Home  >  Article  >  Backend Development  >  How to Retrieve Request Payload in PHP from Ajax Store Operations?

How to Retrieve Request Payload in PHP from Ajax Store Operations?

DDD
DDDOriginal
2024-11-10 05:59:02129browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn