note 125783 added to function.json-decode

From: Date: Sat, 06 Feb 2021 20:51:23 +0000
Subject: note 125783 added to function.json-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-219302@lists.php.net to get a copy of this message
if you're using ajax to post, and your JavaScript code looks like this: <code> var xhttp = new XMLHttpRequest(); xhttp.open("POST", "something.php", true); xhttp.setRequestHeader("Content-Type", "application/json"); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { // do something } }; var data = {some: "thing"}; xhttp.send(JSON.stringify(data)); </code> then in <code>something.php</code> you can retrieve your json by doing <?php $data = json_decode(file_get_contents("php://input"), true); ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.159.166 (proxied: 95.252.227.138) ---- Manual Page -- http://php.net/manual/en/function.json-decode.php Edit -- https://master.php.net/note/edit/125783 Del: integrated -- https://master.php.net/note/delete/125783/integrated Del: useless -- https://master.php.net/note/delete/125783/useless Del: bad code -- https://master.php.net/note/delete/125783/bad+code Del: spam -- https://master.php.net/note/delete/125783/spam Del: non-english -- https://master.php.net/note/delete/125783/non-english Del: in docs -- https://master.php.net/note/delete/125783/in+docs Del: other reasons-- https://master.php.net/note/delete/125783 Reject -- https://master.php.net/note/reject/125783 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#219302) next »