0

这个问题已经阻塞了我的错误日志很长一段时间了。该功能正在做我想做的事情,但是这条消息让我发疯了!

function togglePreview( link_id ) {  
        var data = { ajax_cmd: 'get_embed_html', link_id: link_id };
        jQuery.post("?", data, function(json) {
            if (json.html) {
                jQuery( "#listen_" + link_id ).html( json.html );
            }
        }, "json"); 
}

服务器端,我有几行 PHP:

<?php
header('Content-Type: application/json');
$html = get_embed_html( $_REQUEST['link_id'] );
echo json_encode( array("html" => $html) ); 
?>

来自服务器的 JSON 字符串输出如下:

{"html":"<iframe frameborder=0 height=400 width=100% src='http:\/\/www.youtube.com\/watch?v=ozhtg6FuD8A'><\/iframe><noscript>JavaScript is required to load the comments.<\/noscript>\n<div class=\"inline-comments-container\" name=\"comments\">\n    <div id=\"inline_comments_ajax_handle\" class=\"last-child\" data-post_id=\"26\">\n    <div id=\"inline_comments_ajax_target\" style=\"display: none;\"><\/div>\n    <div class=\"inline-comments-loading-icon\">Loading Comments&#8230;<\/div>\n    <input type=\"hidden\" name=\"inline_comments_nonce\" value=\"c16a7993ab\" id=\"inline_comments_nonce\" \/>\n            <div class=\"inline-comments-content\">\n            <div class=\"inline-comments-p\">\n                <form action=\"javascript:\/\/\" method=\"POST\" id=\"default_add_comment_form\">\n                    <input type=\"hidden\" name=\"inline_comments_nonce\" value=\"c16a7993ab\" id=\"inline_comments_nonce\" \/>\n                    <span class=\"inline-comments-profile-pic-container\"><img alt='' src='https:\/\/graph.facebook.com\/FACEBOOKID\/picture?type=large' class='avatar avatar-32 photo' height='32' width='32' \/><\/span>                    <textarea placeholder=\"Press enter to submit comment&#8230;\" tabindex=\"4\" id=\"comment\" name=\"comment\" id=\"inline-comments-textarea\" class=\"inline-comments-auto-expand submit-on-enter\"><\/textarea>\n                    <!--<span class=\"inline-comments-more-handle\"><a href=\"#\">more<\/a><\/span>-->\n                    <div class=\"inline-comments-more-container\" style=\"display: none;\">\n                        <div class=\"inline-comments-field\"><input type=\"text\" tabindex=\"5\" name=\"user_name\" id=\"inline_comments_user_name\" placeholder=\"Name&#8230\" value=\"greeny\"  \/><\/div>\n                        <div class=\"inline-comments-field\"><input type=\"email\" required tabindex=\"5\" name=\"user_email\" id=\"inline_comments_user_email\" placeholder=\"Email&#8230\" value=\"email@example.com\"  \/><\/div>\n                        <div class=\"inline-comments-field\"><input type=\"url\" required tabindex=\"6\" name=\"user_url\" id=\"inline_comments_user_url\" placeholder=\"Website&#8230\" value=\"\" \/><\/div>\n                    <\/div>\n                <\/form>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>"}

调用 JS 函数 togglePreview(4) 时,我收到以下错误代码:

Uncaught SyntaxError: Unexpected token )

希望这是我忽略的非常简单的事情!

4

1 回答 1

0

难道是你有magic_quotes_runtime?这可以将随机转义字符添加到您的 json 字符串中。

于 2013-05-16T19:46:10.583 回答