我想each
在下面的 js 代码中为 json 完成,但是我有错误Uncaught TypeError: Cannot read property 'length' of null
并且它不起作用,我该怎么办?
json代码:
[
{
"type_bad":"5"
},
{
"type_bad":"5"
},
{
"type_bad":"14"
},
{
"type_bad":"6"
},
{
"type_bad":"13"
},
{
"type_bad":"3"
},
{
"type_bad":"8"
}
]
我的js代码:
$('.TypeRoom').live("change", function (e) {
val = 'id_units=' + id + 'type_room=' + type_room;
$.ajax({
type: "POST",
dataType: 'json',
url: 'get_unitsTB',
data: val,
cache: false,
success: function (units) {
$.each(units, function (index, val) {
alert(val.type_bad);
});
},
"error": function (x, y, z) {
// callback to run if an error occurs
alert("An error has occured:\n" + x + "\n" + y + "\n" + z);
}
});
});