Answer the question
In order to leave comments, you need to log in
jQuery, JSON, iframe and quotes not working together?
I upload a file in an iframe (it seems to be no other way). As a response, I generate a JSON object where one of the fields is a line with html describing the error.
Question: How can 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 "fixes" the html and after that it's not possible to deserialize the JSON because the quotes lose the escape character. we get Invalid JSON.
Answer the question
In order to leave comments, you need to log in
Try to encode urlencode on the server before sending the HTML to the client, decode it with javascript on the client via decodeURI or unescape.
How do you generate and receive json?
For data like this
{"html":"<a href=\"#\">!!!<\/a>"}
<html>
<head>
<script type="text/javascript" src="http://yandex.st/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.getJSON('j.php', '', function (data) {$('body').html(data.html);});
}
);
</script>
</head>
<body>
</body>
</html>
give in the iframe not json, but full-fledged html + javascript:
<script>parent.callback_func({json: "data"});</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question