Skip to content
Advertisement

How to Stringify one JSON object while keeping the other an integer

On the PHP side of things, I have an integer and I have a string of HTML:

JavaScript

$versionid is just an integer and $htmlstuff is a reasonable string of HTML. I escaped the double quotes trying to resolve this.

When I parse this as such on the JQuery/JS side, I get an unexpected token error. Previously, I was only sending the string of HTML by itself without the JSON array and all was fine.

JavaScript

Advertisement

Answer

My solution to this problem was simple. Instead of attempting to echo the JSON myself, I put it into a PHP array and used JSON_ENCODE to prep it for jQuery and this ended up working fine.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement