I am using the wp_ajax_
and wp_ajax_nopriv_
in localize script I am passing a big multidimensional array( it's big!). It works without any JSON encode, decodes. But I want to encode it is while I make ajax call...so I used
json_encode
in localizing script (wp_json_encode also gives the same output).. I pass it through ajax data parameter.
now when I access that as json_decode($_POST['largejson'], true)
i get the response but not as an array but a string with lot of backslashes
\":[{\"field_type\":\"shortcode_elementor_pro\",\"_id
what could be possibly going wrong?
update i use this to debug it
if ($data_settings === null){
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
it showed - Syntax error, malformed JSON'; so json_encode might be the problem maker
I am using the wp_ajax_
and wp_ajax_nopriv_
in localize script I am passing a big multidimensional array( it's big!). It works without any JSON encode, decodes. But I want to encode it is while I make ajax call...so I used
json_encode
in localizing script (wp_json_encode also gives the same output).. I pass it through ajax data parameter.
now when I access that as json_decode($_POST['largejson'], true)
i get the response but not as an array but a string with lot of backslashes
\":[{\"field_type\":\"shortcode_elementor_pro\",\"_id
what could be possibly going wrong?
update i use this to debug it
if ($data_settings === null){
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
it showed - Syntax error, malformed JSON'; so json_encode might be the problem maker
Share Improve this question edited Jan 13, 2020 at 14:19 asked Jan 13, 2020 at 13:56 user145078user1450781 Answer
Reset to default 0This fixed my issue $set = stripslashes($set);