ajax为什么返回html标签,AJAX与特定值后返回的HTML标签
我想寫使用jQuery的post.I傳遞的參數(shù),以ajax.php并獲得josn數(shù)據(jù)添加用戶注釋代碼,如下:AJAX與特定值后返回的HTML標(biāo)簽
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);
我的問(wèn)題是jQuery的返回許多不敬html標(biāo)簽wihth JSON數(shù)據(jù)作為下面
{"msg":"hello","cid":"600"}
解決這個(gè)問(wèn)題最簡(jiǎn)單的方法是什么? 在此先感謝!
+1
發(fā)布您的ajax.php完整代碼?它有問(wèn)題。 –
+1
是不是$ classobj> add_comment這應(yīng)該是$ classobj - > add_comment? –
+0
你還有別的'echo'聲明嗎?嘗試評(píng)論'echo json_encode($ ajax);'并且看看你得到了什么結(jié)果。或者嘗試在'echo'后面加上'exit'并查看結(jié)果。 –
總結(jié)
以上是生活随笔為你收集整理的ajax为什么返回html标签,AJAX与特定值后返回的HTML标签的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 萝卜为什么出现黄心?
- 下一篇: 吃什么疏菜可以减肥?