Passing x-data (JSON) from php #1325
-
I'm trying to pass data generated server side into x-data but hit an error when referencing JSON. Is there a simple solution to this? This isnt a livewire project, just PHP with alpine on the front end. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I assume you printed the json without escaping it so you generated something like you can use htmlspecialchars to escape the string when printing it out. If that's not the issue, you need to post the generated HTML so people can replicate and try to help. |
Beta Was this translation helpful? Give feedback.
I assume you printed the json without escaping it so you generated something like
<div x-data="{"foo": "bar"}">
.That is going to confuse the browser because of the multiple quotes (it will think that x-data is just
"{"
).you can use htmlspecialchars to escape the string when printing it out.
If that's not the issue, you need to post the generated HTML so people can replicate and try to help.