jquery json php

1 Cevap php
 while ($row = mysql_fetch_object($result)) {
    $data[] = $row;
    echo "<div id='captionbox' style='width: 110px;float:left;color:#FFF;text-align:center;'>";
    echo "<a href='#' class='thumb'><img class='thumb-img' value = ".$row->aid." onclick='getVote(".$row->aid.", \"".$row->atitle."\")' src='images/roadies/th".$row->aid.".jpg' />	</a>";
    echo "<input  type = hidden name = aid id = rd".$row->aid." value = ".$row->aid.">".$row->atitle."</input>";
    echo "</div>";
    }

    $jsfriend = json_encode($data);

the above is my php code. i want the $data to be a JSON object. now i want to import it in my javascript file and use as a JSON object by using Jquery. But I am completely lost in the docs. there is a PHP example for doing things, but that includes some #id example i dont understand. can someone build me a Jquery function for this?

teşekkürler şimdiden bir sürü.

*EDIT - What I am trying to do * I am trying to get the JSON object jsfriend in to my javascript file, script.js. I dont know how to use the Jquery function. If someone could explain it. Also tell me once the JSON object is in the javascript, how do i access values from the JSON object?

EDIT 2: my JSON string reads like this:

[{"aid":"1","atitle":"Ameya R. Kadam"},{"aid":"2","atitle":"Amritpal Singh"},{"aid":"3","atitle":"Anwar Syed"},{"aid":"4","atitle":"Aratrika"},{"aid":"5","atitle":"Bharti Nagpal"}]

"1": Ben yardım için adını görüntülemek isterseniz birisi bana Javascript söyleyebilir?

1 Cevap

Bir JSON dize javascript doğrudan kullanılabilmektedir.

echo '<script type="text/javascript">';
echo 'var foo = '.json_encode($data);
echo 'alert(foo[0].column_name);';
echo '</script>';