我想写使用jQuery的post.I传递的参数,以ajax.php并获得josn数据添加用户注释代码,如下:AJAX与特定值后返回的HTML标签
var formObjectData = $('#' + form_id).serialize() + '&flag=add_comment'; // all
$.post(
'http://192.168.3.3/myblog/ajax.php',formObjectData,
function(data) {
if (!data)
alert("No data");
else {
if (data.msg!='')
$("#add_comment").html(data.msg);
}
},
'json'
);
上ajax.php
$cid = $classobj->add_comment($comment,$id); // to add the comment in db and return the comment id
$ajax['msg'] = $msg ? $msg : '';
if ($cid) {
$ajax['cid'] = $cid;
}
echo json_encode($ajax);
我的问题是jQuery的返回许多不敬html标签wihth JSON数据作为下面
{"msg":"hello","cid":"600"}
解决这个问题最简单的方法是什么? 在此先感谢!
+1
发布您的ajax.php完整代码?它有问题。 –
+1
是不是$ classobj> add_comment这应该是$ classobj - > add_comment? –
+0
你还有别的'echo'声明吗?尝试评论'echo json_encode($ ajax);'并且看看你得到了什么结果。或者尝试在'echo'后面加上'exit'并查看结果。 –