开发者

JSON output not properly parsed by JQuery?

As it stands, I have some JQuery along these lines -

ph=function(i){
$.each(i,function(po){
id=po.id;url="/"+id;t=$('<div id='+ id +' class=entry></div>');
t.html('<div class=hx><a href="/users/'+ po.author +'">'+ po.author +'</a></div><div class=b>'+ po.body +'</div>');
t.prependTo($("#modpskx"));
t.hide();
t.slideDown("slow");});};
function mtoxps(){
mid=$("#xsodl").val();
id=$("#modpskx > div:first")[0].id;
if(id==""){id=0}
$.ajax({
url:'/widgets/live.php',
data:{'id':id,'mid':mid},
type:'post',
dataType:'json',
cache:false,
success:function(b){ph(b);}});}
setInterval("mtoxps()", 10000);

The JSON data sent back to the browser by the server is as follows:

[{
  "author": "NiX",
  "timestamp": "2009-12-20 21:35:32",
  "id": "194",
  "mig_id": "3",
  "body": "Cows.",
  "ip": ""
}]

This - every 10 seconds - successfully requests any new results. Unfortunately, the "ph" variable (what is used to return and display the result(s)) isn't properly parsing the returned output. Instead, it displays all the variables as undefined, resulting in the开发者_StackOverflow next request to send the server an "undefined" variable, as well.

Are there any suggestions as to why this isn't functioning?


Try:

$.each(i, function(index, po){

instead of

$.each(i, function(po){

The callback for the each function is at the bottom of this page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜