I'm trying to use a php array in my JavaScript part of my Website by encoding it to Json and sending it over an echo but compiling the website and visiting it over chrome gives me a broken website with a Json file that stops halfway through start of file end of file
the website works fine when I'm not encoding my Json and Json file is only 265 kb big so I guess the website should be able to handle that under normal conditions.
Also here is the relevant part of the code if this helps:
<script type="javascript">
function confirmSelection(i) {
if (confirm("Sure you want to load new Song?")) {
let tags = {"'id'", "'number'", "'name'", "'slug'", "'way'",
"'language'", "'category'", "'year'", "'lyrics_author'",
"'melody_author'", "'position'", "'url'", "'update_time'", "'paragraphs'"};
let currentTags = {"'currentId'", "'currentNumber'", "'currentName'",
"'currentSlug'", "'currentWay'", "'currentLanguage'",
"'currentCategory'", "'currentYear'", "'currentLyrics_author'",
"'currentMelody_author'", "'currentPosition'", "'currentUrl'",
"'currentUpdate_time'", "'currentParagraphs'"};
<?php $json = json_encode($editor->lieder); ?>
let lieder = <?php echo $json; ?>;
for (let j = 0; j < tags.length; j++) {
document.getElementById(currentTags[j]).value = lieder[i][tags[j]];
}
}
}
</script>
question from:
https://stackoverflow.com/questions/65642837/problems-with-encoding-my-php-array-to-show-in-my-javascript-code 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…