Skip to content
Discussion options

You must be logged in to vote

@kingma-sbw You’re running into this because you’re calling json_encode() on a string, not on an actual JSON-object.
Since $_GET['message'] is empty json_encode("{}") is being called, which results in "\"{}\"".

A solution would be to check $_GET['message'] first and depending on that encode it or return the JSON-Object:

<?php
$message = isset($_GET['message']) ? json_encode($_GET['message']) : "{}";
?>
...
  <div
    id="app"
    data-message="<?= $message ?>"
  >
  </div>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kingma-sbw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants