jQuery : 有关TypeError: invalid ‘in’ operand obj的错误
参考 lwx2615 的博客 ,网站: http://blog.csdn.net/lwx2615/article/details/9668777
由PHP返回一个json数据
$.ajax({ url:"<?= \yii\helpers\URL::to(['sign/search']) ?>", type:"get", data:"time1="+time1+"&time2="+time2, success:function(msg){ var str = new String(); $.each(msg, function(a,b){ str+="<tr>"; str+="<td>"+b.indent+"</td>"; str+="<td>"+b.user+"</td>"; str+="<td>"+b.time+"</td>"; str+="<td>"+b.hao+"</td>"; str+="<td>"+b.movie+"</td>"; str+="</tr>"; });
使用each解析时候,就会报错TypeError: invalid ‘in’ operand obj。
改为
$.ajax({ url:"<?= \yii\helpers\URL::to(['sign/search']) ?>", type:"get", data:"time1="+time1+"&time2="+time2, success:function(msg){ var str = new String(); obj= $.parseJSON(msg); //转化一下数据 $.each(obj, function(a,b){ str+="<tr>"; str+="<td>"+b.indent+"</td>"; str+="<td>"+b.user+"</td>"; str+="<td>"+b.time+"</td>"; str+="<td>"+b.hao+"</td>"; str+="<td>"+b.movie+"</td>"; str+="</tr>"; }); $("#table").html(str); }