Javascript jQuery | Ajax | json:循环不工作
在我决定整理代码之前,这一切都很顺利。现在我已经尝试了很多东西,我甚至不知道它原来是什么 这是我的json响应Javascript jQuery | Ajax | json:循环不工作,javascript,jquery,json,ajax,Javascript,Jquery,Json,Ajax,在我决定整理代码之前,这一切都很顺利。现在我已经尝试了很多东西,我甚至不知道它原来是什么 这是我的json响应 Array ( [26892] => Array ( [uid] => 26892 [subject] => LAST DAY [mailbox] => abc [date] => Oct 1 [host] =
Array
(
[26892] => Array
(
[uid] => 26892
[subject] => LAST DAY
[mailbox] => abc
[date] => Oct 1
[host] => sstock.com
)
[5418] => Array
(
[uid] => 5418
[subject] => ENJOY
[mailbox] => abc
[date] => Feb 8
[host] => stock.com
)
[5178] => Array
(
[uid] => 5178
[subject] => SUPER
[mailbox] => box1
[date] => Feb 6
[host] => stock.com
)
下面是混乱的代码现在的样子
var htmlStr = '';
$.ajax({
url: 'data.php',
data: {data: 'nz-json', from_mailbox: mailbox, from_host: host},
type: 'GET',
dataType: 'json',
beforeSend: function(){
$('.nz-getnewz-spinner').show();
},
success: function(output) {
$.each(output, function(k, v) {
htmlStr += '<div from-host="'+v.host+'">'+v.mailbox+'</div>';
});
$('.nz-getnewz-spinner').hide();
$('#output-div').html(htmlStr);
if (uid === undefined) {
// do stuff
} else {
//do other stuff
}
}
});
我几乎要从头开始重写了,但在此之前,我希望somoene能指出任何明显的问题
谢谢。从基本调试开始,在
success
函数中添加console.log(typeof output,output)
并查看您将立即获得的信息。我一直在尝试调试,但没有想到“typeof”。谢谢你的回答?哪里检查php,json_encode,将其序列化,使其立即工作。哇!但愿我几个小时前就在这里贴了。我所做的改变是正确的。1.远离的。2.生成json响应的php函数有。。。返回json_decode($list);。。我把解码步骤移到了响应的功能上。太棒了!添加并接受您自己的答案
Uncaught TypeError: Cannot use 'in' operator to search for 'length' in