2017-10-04 76 views
-1

我似乎無法弄清楚爲什麼我得到這個錯誤我已經看到了錯誤的解決方案,但沒有人使用AJAX來獲取數據,如果有人可以幫助將是巨大的,這裏的JS:不能使用'in'運算符搜索'長度'

$(document).ready(function() { 
    function updatetabel() { 
     console.log("update"); 
     $.ajax({ 
      url: "/main", 
      type: 'GET', 
      dataType: "", 
      cache: false, 
      success: function(result) { 
       console.log("succes!"); 
       console.log() 
       $(".table-hover-cells").remove(); 
       $.each(result, function(index, value) { 
        console.log("update_tabel"); 
        var content = "<table class=\"table-hover-cells" + 
         this[0] + "\" id=\"hover-table\">" + "<thead>" + "<tr>" + "<td>" + 
         this.Name + "</td>" + "<td>" + 
         this.Description + "</td>" + "<td>" + 
         this.Status + "</td>" + "<td>" + 
         this.Date + "</td>" + "</tr>" + "</thead>" + "</table>" 

        $("inv").append(content); 
       }) 
       console.log("tabel_update"); 
      }, 
      error: function(result, thrownError) { 
       console.log("Failure!") 
       console.log(result) 
      } 
     }); 

    } 

    updatetabel(); 
    setInterval(function() { 
     updatetabel() 
    }, 100000); 
}); 

$(document).ready(function() { 
    $('table tbody tr td').on('hover', function() { 
     $(this).toggleClass('bg'); 
    }); 
}); 
+1

你的代碼中的哪一行會拋出該錯誤? – Terry

+0

任何你將數據類型留空的原因,而不是把'json'? – Keith

+0

哪裏使用'.length'? – Niladri

回答

2

在你的成功回調以下行引發錯誤:

$.each(result, function(index, value) { 
    ... 
} 

最有可能的,你的「結果」是不是你的要求有效響應和$ .each需要一個有效的數組來遍歷。首先檢查ajax調用的XHR響應,看看是否返回數組。也最好定義你的dataType。

相關問題