Sorry i see that here is heap of similar questions, but i will be dare to ask the same. I'm sending javascript two dimensional array to PHP script and then it saved to database. I'm using JSON.stringify and have such string in the database
[["babaguliala","979485","xlopa kupa 12"],["didoboroda","222455","nemadoma 12"]]
But when i try to retrieve this array and parse it i got an error. This is part of PHP fubction that sends array to javascript:
$organizations = get_user_meta($current_user_id, 'organizations');
echo $organizations;
But when i try to parse this data i'm getting error:
console.log( 'response: ' + response ); // response: Array
organizations =JSON.parse(response); // Error
Error detail is here:
Uncaught SyntaxError: Unexpected token A in JSON at position 0
at JSON.parse (<anonymous>)
at Object.success ((індекс):562:24)
at c (jquery.min.js?ver=3.6.0:2:28327)
at Object.fireWith [as resolveWith] (jquery.min.js?ver=3.6.0:2:29072)
at l (jquery.min.js?ver=3.6.0:2:79901)
at XMLHttpRequest.<anonymous> (jquery.min.js?ver=3.6.0:2:82355)
But when it try thiscode enter into console:
const ajaxResponse = '[["babaguliala","979485","xlopa kupa 12"],["didoboroda","222455","nemadoma 12"]]'
const arr = JSON.parse(ajaxResponse)
I'm getting nice response and parsing went right.
arr[0] // ["babaguliala", "979485", "xlopa kupa 12"] (3)
arr[1] // ["didoboroda", "222455", "nemadoma 12"] (3)
Sorry but i do not understand what this behaviour mean. Could someone explain ?