How to reference array JSON/HTML data types on JQUERY SUCCESS handler
<p>I am trying to update multiple items, in the case span tags, through JQuery. I did manage to update a single item, using html dataType, but I have been unable to find the correct way to reference an array of items.</p>

<p>The problem seems to be in the setData function below. I was attempting to reference it as an ordinary array, but that does not seem to work.</p>

<p>This is the JQuery:</p>

<pre><code>&lt;script&gt;
$(document).ready(function () {
    $(".hook1").change(function () {
        pass_id = (this.value);
        var seltop = $(this).attr('id');
        var lastchar = seltop.slice(-1);
        $.ajax({
            type: "POST",
            url: "comp_data.php",
            dataType: "json",
            data: {
                passval: pass_id,
                pass2: lastchar
            },
            success: function setData(data) {
                $("#price" + lastchar).html(data[0].price);
                $("#matricule" + lastchar).html(data[1].matricule);
                $("#tag" + lastchar).html(data[2].tag);
                $("#ins_yr1" + lastchar).html(data[3].ins_yr1);
                $("#Totalacq" + lastchar).html(data[4].Totalacq);
            }

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

<p>This is the relevant portion of the comp_data.php file:</p>

<pre><code>&lt;?php
$version_id = $_REQUEST['passval'];
$i = $_REQUEST['pass2'];

mysql_query("CREATE OR REPLACE VIEW vcomp AS (SELECT......");

$return = array(
    "price" = &gt; "",
    "matricule" = &gt; "",
    "tag" = &gt; "",
    "ins_yr1" = &gt; "",
    "Totalacq" = &gt; ""
);

$name = array_keys($return);
$ct = count($name);
$n = 0;
while ($n &lt; $ct) {
    $key = $name[$n];
    $sql2 = mysql_query("SELECT *
    FROM vcomp
    ORDER BY segment_id,price
    ");
    while ($row = mysql_fetch_assoc($sql2)) {
        $return[$key] = $row[$key];
    }
    $n++;
}
$returnJSON = json_encode($return);
echo $returnJSON;
</code></pre>

<p>This last echo of $returnJSON gives</p>

<pre><code>{"price":"1014000","matricule":"10000","tag":"6000","ins_yr1":"25350","Totalacq":"1055350"}  
</code></pre>

<p>And that's what I want to output with the setData function.<br>
I appreciate any ideas.</p>
