Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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);
share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
thanks, that was very useful, just was i neeed to know. –  William Aug 29 '09 at 19:08
1  
See docs.jquery.com/Ajax/jQuery.getJSON for more. –  meder Aug 29 '09 at 19:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.