I am passing a JSON object via ajax to my php file. Then I use the function json_encode
, and save it to the database.
The problem is, when the JSON object is empty {}
, then in PHP it is not an empty object/array, but it is an empty string ""
.
I need to deserialize it as encoded (empty JSON object), not as an empty string.
What am I doing wrong?
JQUERY:
_key = $(this).data('column-name');
_temp = {};
$(this).find('> .rc-picker-content > .rc-picker-item').each(function (__index, $__element) {
_temp[__index] = {};
_temp[__index] = $(this).attr('data-value');
});
_attr[_key] = _temp; //the variable which is sent via ajax to php
PHP
if (isset($_POST['value']) && is_array($_POST['value'])){
$_POST['value'] = json_encode($_POST['value']); //this hould be enmpty array not empty string
}