Traverse JSON data with jQuery
<p>I can't figure out how to get a bunch of MySQL rows into a JSON data structure and iterate each of the row fields in java script.</p>

<p>Here is my query in codeigniter</p>

<pre><code>function get_search_results() {

    //$this-&gt;db-&gt;like('title', $searchText);
    //$this-&gt;db-&gt;orderby('title');
    $query = $this-&gt;db-&gt;get('movies');

    if($query-&gt;num_rows() &gt; 0) {

        foreach($query-&gt;result() as $movie) {

            $movies[] = $movie-&gt;title;                

        }

    }

    return $movies;

}
</code></pre>

<p>Encode array for json</p>

<pre><code>$rows= $this-&gt;movie_model-&gt;get_search_results();
echo json_encode($rows);
</code></pre>

<p>My jQuery AJAX request, </p>

<pre><code> $.ajax({
      type: "GET",
      url: "publishlinks/search_movies",
      data: searchString,
      ...
</code></pre>

<p>This is how I've been trying to traverse rows in the java script. It is iterating over every character: 1 t 2 h 3 e 4 g ... 7 e
I need this: 1 the game 2 lost 3 you</p>

<pre><code>   success: 
      function(result) {                                
        $.each(result, function(key, val) {
        alert(key + ' ' + val);
      })

//alert(result);
}
</code></pre>
