How to access members of associative array from AJAX Response
<p>I have a shorthand ajax call that triggers on a selection box change.</p>

<pre><code>&lt;script type'text/javascript'&gt;
    $('#selection_project').change(function(event) {
        $.post('info.php', { selected: $('#selection_project option:selected').val()},
            function(data) {
                $('#CTN').html(data);
           }
       );            
   }); 
&lt;/script&gt;
</code></pre>

<p>It works, but the response from the server is this: </p>

<pre><code>if (isset($_POST['selected']))
    $selected = $_POST['selected'];
    $results['selected'] = $selected;
    $response = json_encode($results);

    echo $response;
</code></pre>

<p>$results is an associative array with many values from a SQL query.</p>

<p>My question is how do I access any particular element?
I've tried things like</p>

<pre><code>data.selected
</code></pre>

<p>or,</p>

<pre><code>data['selected']
</code></pre>

<p>I also understand that somewhere in the .post method there should be a statement defining the alternative dataType, such as </p>

<pre><code>'json', 
</code></pre>

<p>or a </p>

<pre><code>datatype: 'json',
</code></pre>

<p>but after lots of searching, not a single example I could find could provide the actual syntax of using alternative dataTypes in the .post method. 
I would have just used the .ajax method but after pulling my hair out I cannot figure out why that one isn't working, and .post was, so I just stuck with it.
If someone could give me a little push in the right direction I would appreciate it so much!!</p>

<p>EDIT: Here is my .ajax attempt, can't figure out why it's not working. Maybe i've been staring at it too long. </p>

<pre><code>&lt;script type'text/javascript'&gt;

    $('#selection_project').change(function(event) {
        $.ajax({ 
            type: 'POST',
            url : 'pvnresult.php',
            data: { selected: $('#selection_project option:selected').val()},
            dataType: 'json',
            success: function(data){
                $('#CTN').html(data);
            }
        });
    });

&lt;/script&gt;
</code></pre>