Hello im尝试在jquery中使用post从我的php文件中读取数据,并将其作为json对象导出到js脚本中。
但我有个问题。。。我使用firebug控制台,我有一个错误:无效标签。。。
这是我的PHP代码:
$query=mysql_query("SELECT * FROM abonenci WHERE $where");
$row=mysql_fetch_assoc($query);
json_encode($row);
这是我的jquery代码:
$.post("ajax/domeny_abonenci.php", { pesel: get_pesel, nip: get_nip },
function(data){
alert(data.nip);
}, "json");
您的HTTP头是否设置为json?
<?php
header('Content-type: application/json');
尝试引用您的数据:
{ "pesel": "get_pesel", "nip": "get_nip" }
是否正在回显编码的json数据?
无论如何,在您的PHP文件中,尝试以结尾
echo "(".json_encode($row).")";
exit;
这应该可以解决问题。
添加"("before and")"和数据末尾。这应该能解决问题。
请参阅此链接:
http://willcode4beer.com/tips.jsp?set=jsonInvalidLabel
p.s.你需要加上"("answers")"。对不起,我打不出"{"}。我现在已经修复了。
Post函数的第三个参数是一个成功函数(data,textStatus),在我们发送Post表单后会发生什么。在这个函数中,"data"返回成功的Post,"textStatus"返回最终的ajax状态。我相信您的响应中确实没有NIP参数,所以data.NIP是未定义的。