views:

359

answers:

1

Hey

I have an external file in php, outputed as json format

I want the data to be send back to jquery in arrays .... how to do it ?

php:

$options = "<option value="data0">data 0<option>
<option value="data1">data 1<option>
<option value="data2">data 2<option>
<option value="data3">data 3<option>
<option value="data4">data 4<option>";

$arr = array("options" => $options);
echo json_encode($arr);

jquery json:

var new_data = ' data.options ';

$(div_list).html(new_data);
+2  A: 

Maybe something like this?

<script>
$(document).ready(function(){
    $.getJSON("/resource/",
        function(data){
          $.each(data.options, function(i,item){
          $('#select').append( $(item) );
          });
        });
  });

</script>

Though I really can't tell without looking at the exact JSON output.

meder
thanks, that was very useful, just was i neeed to know.
See http://docs.jquery.com/Ajax/jQuery.getJSON for more.
meder