note 90976 modified in function.urldecode by danbrown
| From: | danbrown@php.net | Date: | Tue, 19 May 2009 11:51:20 +0000 |
| Subject: | note 90976 modified in function.urldecode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155724@lists.php.net to get a copy of this message | ||
Send json to PHP via AJAX (POST)
If you send json data via ajax, and encode it with encodeURIComponent in javascript, then on PHP
side, you will have to do stripslashes on your $_POST['myVar'].
After this, you can do json_decode on your string.
Ex.:
<?php
// first use encodeURIComponent on javascript to encode the string
// receive json string and prepare it to json_decode
$jsonStr = stripslashes ($_POST['action']);
// decode to php object
$json = json_decode ($jsonStr);
// $json is now a php object
?>
--was--
Send json to PHP via AJAX (POST)
If you send json data via ajax, and encode it with encodeURIComponent in javascript, then on PHP
side, you will have to do stripslashes on your $_POST['myVar'].
After this, you can do json_decode on your string.
Ex.:
// first use encodeURIComponent on javascript to encode the string
// receive json string and prepare it to json_decode
$jsonStr = stripslashes ($_POST['action']);
// decode to php object
$json = json_decode ($jsonStr);
// $json is now a php object
http://php.net/manual/en/function.urldecode.php