E
E
Extramezz2015-05-30 12:55:00
JSON
Extramezz, 2015-05-30 12:55:00

What causes the "unterminated string literal" error?

In general, we have the following picture in one folder:
1. A PHP file that, when requested, "returns" a binary array in JSON format using the json_encode() function; . That is, something like this:

[ { "1": "A", "2": "C", "3": "D"}, { "11": "OLOLO" } ]

2. Page, also PHP, where there is such a line:
<script type="text/javascript">
      var CatTheColors = JSON.parse('<?php echo file_get_contents("tot_file_vishe.php"); ?>');
</script>

Well, after loading the page in the source code, I see:
var CatTheColors = JSON.parse('[
    {
        "1": "A",
        "2": "C",
        "3": "D",
    },
    {
        "11": "OLOLO"
    }
]');

And in the console, the browser swears at "unterminated string literal", that is, at the first line of code above. Why? What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Extramezz, 2015-05-31
@Extramezz

And 1 more question. Moved the first PHP file to a directory above, writing I
get an error about the "Non-existence" of this file, although it is 100% there :\
Why?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question