1

I have this code:

PHP
function print_json(){
    //code...
    $rows = $stmt->fetch(PDO::FETCH_ASSOC);
    $images = json_encode($rows);
    echo $images;
}
JAVASCRIPT
var json = JSON.parse('<?php print_json(); ?>');
console.log(json);

The console error is: "Uncaught SintaxError: Unexpected token in JSON at position 188 at JSON.parse () at name of my page"

This error appeared for the first time when the extraction contained some base64 images, I did some tests and I found that it also shows errors with strings like 'hi \ hi'. The problem is the character '\', why json_encode don't fix the escape problem with that character?

Question
  • 145
  • 2
  • 12

0 Answers0