JQuery, JSON, iframe, and quotation marks do not work together

Produce upload file in an iframe(a different kind of way). In response, generate a JSON object where one of the fields is a string with the html describing the error.
Question: How do I get this response from the server without breaking it?

When I use .text() from JQuery all tags are removed.
When I use .html() from JQuery it "corrects" the html and then it is not possible to do the deserialization of the JSON because the quotes are losing the escape character. we get Invalid JSON.
October 14th 19 at 12:11
4 answers
October 14th 19 at 12:13
Solution
Try on the server before sending to the client the HTML to encode urlencode on the client om JavaScript decode using decodeURI or unescape.
I do not want the extra time to encode-decode, and with urlencode much size will increase 2-3 times. - Mittie.Witti commented on October 14th 19 at 12:16
Then on the server using str_replace (talking about PHP?) be replaced only > with %3e, < to %3c, "on %22 and' to %27. - Evan.Moen commented on October 14th 19 at 12:19
Talking about Python, but it doesn't matter. While sahail with .replace("<","\u003c").replace(">","\u003e") have already serializing object. The browser has ceased to be clever and spoil my "invalid" HTML.
Thanks for the tip. - Mittie.Witti commented on October 14th 19 at 12:22
After a moment of thought, tried so. Ie in your case, you can replace special HTML characters to their entities (< > " '), and the client to use .text() — I think that will work without decoding. - Evan.Moen commented on October 14th 19 at 12:25
October 14th 19 at 12:15
.getJSON is not able to uploading files. That's the problem. - Mittie.Witti commented on October 14th 19 at 12:18
Then use $.parseJSON() to handle response from the server. - Evan.Moen commented on October 14th 19 at 12:21
And anyway, what's getJSON? This is the short version

$.ajax({
url: "...",
dataType : "json",
data: '...',
success: cb_function
});
- Mittie.Witti commented on October 14th 19 at 12:24
So I use $.parseJSON(), the problem is that I can't get the iframe is not damaged response. While solved the problem with replace characters < > in their codes. But I don't like this decision. - Evan.Moen commented on October 14th 19 at 12:27
Can the code lead? It would be interesting to understand. - Mittie.Witti commented on October 14th 19 at 12:30
October 14th 19 at 12:17
to give in the iframe, not json, and a full html + javascript:
the <script>parent.callback_func({json: "data"});</script><br>
October 14th 19 at 12:19
innerHTML?
.html() is a wrapper for the innerHTML. So that gives the same fixed html. - Mittie.Witti commented on October 14th 19 at 12:22

Find more questions by tags JSONHTMLiframejQuery