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

DDD
Release: 2024-11-10 05:59:02
Original
145 people have browsed it

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');
Copy after login

If the payload is in JSON format, decode it with:

$data = json_decode($request_body);
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template