Uncaught SyntaxError: Unexpected token)在解析JSON字符串时
Uncaught SyntaxError: Unexpected token ) when parsing JSON string with HTML inside
这个问题已经堵塞了我的错误日志很长一段时间了。这个函数正在做我想让它做的事情,但是这个消息让我发疯了!
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…<'/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…'" 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…'" 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…'" 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…'" value='"'" '/><'/div>'n <'/div>'n <'/form>'n <'/div>'n <'/div>'n <'/div>'n<'/div>"}
调用JS函数togglePreview(4)时,我收到以下错误代码:
Uncaught SyntaxError: Unexpected token)
希望是我忽略的一些非常简单的东西!
是不是magic_quotes_runtime打开了?这可以在json字符串中添加随机转义字符
相关文章:
- 如何使用JSON字符串中的jQuery填充下拉框
- Json字符串可以'当字符串末尾有“'时,t解码;
- jquery从2个json字符串构建一个复选框表单
- RegEx只匹配JSON字符串中最里面的数组
- json字符串的Javascript帖子:没有任何东西传入或返回
- 使用javascript在MVC视图中解析.net JSON字符串
- 用Angularjs+Typescript将GZip Json字符串解压为普通Json字符串
- 如何将表单数据传递给PHP并将json字符串返回给Javascript
- 如何使用AngularJS应用基于Json字符串响应的条件CSS类
- 停止JSON.parse()从JSON字符串数据中删除尾随零
- 将JSON字符串转换为函数参数
- 在AngularJS中创建JSON字符串
- 为什么我不能使用jQuery.parseJSON(json)解析json字符串
- Json字符串更改日期
- JSON字符串格式错误
- Json和$scope的角度之间的差异$eval应用于JSON字符串时
- C#JSON字符串到JavaScript数组
- 如何在JSON字符串中实现嵌套HTML
- 如何从带有多个对象的JSON字符串创建JSON对象
- 使用捕获组查找和替换json字符串中出现的所有短语