Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community that shares solutions with each other.

If you think you have something to add here.

you are welcome with your fresh ideas - List Articles

PHP - how to receive json POST request?

0 contributions
9 points

In PHP it is possible to receive json request in following way.

1. Parse JSON input stream example

backend.php file:


	function parseInput()
		$data = file_get_contents("php://input");
		if($data == false)
			return null;
		return json_decode($data);

		$data = parseInput();
		echo "  POST request method\n";
		echo "   + Name: " .  $data->name . "\n";
		echo "   + Age: " .  $data->age . "\n";
		echo "Unsupported request method.";

Note: to use different request method read this article.

ajax.htm file:

<!doctype html>
<html lang="en">
    <script src=""></script>
<pre id="response"></pre>

	var handle = document.getElementById('response');

	var data = {
		name: 'John',
		age: 25

        type: 'POST',
        url: '/backend.php',
        data: JSON.stringify(data),
        success: function (data) {
            handle.innerHTML = 'Response:\n' + data;
        error: function(error) {
            handle.innerText = 'Error: ' + error.status;



jQuery POST JSON request to PHP server
jQuery POST JSON request to PHP server


  1. php://input stream - PHP Docs
  2. file_get_contents function - PHP Docs
  3. json_decode function - PHP Docs
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more