Uncaught TypeError: Cannot read property '0' of undefined
<p>I'm making an ajax call using jQuery as below.</p>

<pre><code>$.ajax({
    type: "POST",
    url: "proc.php",
    dataType: 'json',
    data: dataString,
    cache: false,
    success: function(data){
        alert(data.vote[0].line);    //Where error shows
    }
});
</code></pre>

<p>The php page returns <code>echo json_encode($string);</code> which is like</p>

<p><code>"{ 'vote' : [{ 'line' : 'newline1', 'up' : '0', 'down' : '1'},
              { 'line' : 'newline2', 'up' : '4', 'down' : '1'}
             ]}"</code></p>

<p>When I run it, an error comes up saying</p>

<p><code>Uncaught TypeError: Cannot read property '0' of undefined</code> on the line commented above in the ajax call</p>

<p>Can anyone help me point out where am I doing it wrong??</p>

<p>UPDATE:</p>

<p>the variable <code>$string</code> is generated as below </p>

<pre><code>    $comma = ",";
    $success = mysql_query($query, $connection);
    while($row = mysql_fetch_array($success)){
            $voteUp = $row['voteup'];
            $voteDwn = $row['votedwn'];

            $vote .= $comma . "{ 'line' : '{$row['entryid']}', 'up' : '{$voteUp}', 'down' : '{$voteDwn}'";
            $comma = ",";
        }
    $string = "{ 'vote' : [" . $vote . "]}";
    echo json_encode($string);
</code></pre>
