我正在向我的服务器发出请求jQuery.post(),我的服务器正在返回JSON对象(如{ "var": "value", ... }).但是,如果任何值包含单引号(正确转义\'),jQuery无法解析其他有效的JSON字符串.这是我的意思的一个例子(在Chrome的控制台中完成):
data = "{ \"status\": \"success\", \"newHtml\": \"Hello \\\'x\" }";
eval("x = " + data); // { newHtml: "Hello 'x", status: "success" }
$.parseJSON(data); // Invalid JSON: { "status": "success", "newHtml": "Hello \'x" }
Run Code Online (Sandbox Code Playgroud)
这是正常的吗?有没有办法通过JSON正确传递单个引用?
我有一个jquery ajax代码发表评论..
function PostComment()
{
$.ajax({
type :"POST",
url:PageUrl+'Post_LectureComment',
data:"{Comment:'"+$('#txt_PostComment').val()+"',LectureID:'"+87+"',CategoryID:'"+2+"',Author_Id:'"+ 78+"' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success:SuccessHandler ,
});
function SuccessHandler(data)
{}
}
Run Code Online (Sandbox Code Playgroud)
当我在txt_PostComment中使用'like = durgesh'rao发送数据时,它显示错误
请求有效负载:{评论:'durgesh'rao',LectureID:'1250',CategoryID:'2',Author_Id:'135'}
用什么方式发送数据'???