json_encode() can't return html
javascript, jquery, json, php
Solution
Try this:
<?php echo json_encode($snippetData, JSON_HEX_QUOT | JSON_HEX_TAG);
Source
Problem
I'm trying to return some code snippets from php to jquery. Everything works ok, but when I try to return html with `<body>` and `<html>` tags then I get my javascript code in output (raw code) this is my code: ``` $snippetData['snippetId'][] = $snippetId; $snippetData['title'][] = $title; $snippetData['description'][] = $description; $snippetData['snippet'][] = $code; echo json_encode($snippetData); ``` EDIT: To make it more clear this is what I store in this array: ``` snippedId = 5 (integer value) title = 'some title' (string value) description 'some description' (string value) snippet = '<html> <body> <title>some title </title> </body> </html>' (string value) ```