未捕获的TypeError:无法使用'in'运算符进行搜索--Json

时间:2014-05-21 00:28:21

标签: jquery json uncaught-typeerror

我将JSON打印为[{"comments":"ashdhasasbsd"},{"comments":"sdds"}]。但是我的脚本给了我以下错误。知道什么是错的吗?

Uncaught TypeError: Cannot use 'in' operator to search for '74' in Connected to MySQL<br>[{"comments":"ashdhasasbsd"},{"comments":"sdds"}] - 

的jquery-1.10.2.js:997

<a onclick="showUser('.$row['ID'].')" >Show Comments</a>    
<script>
    function showUser(str) {
          if (str=="") {
            document.getElementById("txtHint").innerHTML="";
            return;
          } 
    $.ajax({
        type: 'post',
        url: 'viewCommentsJson.php',
dataType: 'json',
        data: {
            q: str
        },
        success: function (data) {


            var response = "";
            $.each(data, function (index, value) {
                response += value.comments + '<br />';
            });
            $('#txtHint').html(response);
        }
    });
    }
    </script>

1 个答案:

答案 0 :(得分:-1)

在viewCommentsJson.php页面上,请以json格式返回数据,如:

echo json_encode($dat);