I have a trouble with Javascript and PHP: I created a page like this:
<html>
<body>
<iframe id="a" src="iframe.php" width="500" height="200"></iframe>
</body>
</html>
and inside iframe.php
, I just echo the JSON string:
<?php
$json = array(
'status' => 'error',
'html' => '<span class="cool">This is a string</span>'
);
echo json_encode( $json );
What I want is getting the correct raw string echoed by iframe.php
using Javascript (maybe jQuery), and parse it as an JSON object.
But the problem is that I always get the wrong cont开发者_JAVA百科ent. I tried both the method described here and jQuery('iframe').contents().find('body').html()
, but no luck. The span
tag is missed or not formatted correctly.
<script>
var frameId = 'a'; // the frame id in your sample code
var frameHtml = frames[frameId].document.documentElement.innerHTML;
</script>
精彩评论