2

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);

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.