L
L
liq2010-09-14 14:44:16
JavaScript
liq, 2010-09-14 14:44:16

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

4 answer(s)
L
lugansk, 2010-09-14
@liq

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.

E
Eugene, 2010-09-14
@Nc_Soft

How do you generate and receive json?
For data like this

{"html":"<a href=\"#\">!!!<\/a>"}

using getJSON everything shows up fine

<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>

Z
zibada, 2010-09-15
@zibada

give in the iframe not json, but full-fledged html + javascript:
<script>parent.callback_func({json: "data"});</script>

A
Alexander Makarov, 2010-09-14
@SamDark

innerHTML?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question