dimanche 28 juin 2015

JSON.parse(json_string_from_php) produces weird array

I'm having a bit of difficulty with transferring a JSON object from the server to the client-side javascript

I have a rows of data fetched from MySQL query stored into $result

Here's the code:

    var json = '<?= json_encode($result->fetch_all()) ?>';
    var word_list = JSON.parse(json);
    console.log(word_list);     //index.php:23
    console.log(json);          //index.php:24

This is the result in chrome console: number of arrays in the concise version and expanded version don't match

Can someone tell me:
1. Why line 23 shows length of 5 when folded, then only show length of 4 when unfolded?
2. Where did word5 go? FYI, the word that disappears changes every time I refresh.

Aucun commentaire:

Enregistrer un commentaire