json - jQuery how to generate code inside code? -


my question might bit confusing, here do. have script:

<script>    ...some script here...     var audioplaylist = new playlist("2", [     {         name:"lismore",         mp3:"http://example.com/song.mp3"     },     {         name:"the separation",         mp3:"http://example.com/song1.mp3"     }  ]) </script> 

what generate script dynamically using $.get.json

var audioplaylist = new playlist("2", [ $.getjson('http://www.example.com/users', function(data) { $.each(data, function(i,item) { document.write(name: ''item.fname'',) document.write(mp3: "http://example.com/"''+item.song_id+''".mp3") }): }); ]) 

inside <script>

is possible? i've tried script , fails.

it possible generate code dynamically that, there no reason that.

just use map method convert array of data ajax call form need playlist object:

$.getjson('http://www.example.com/users', function(data) {   var items = $.map(data, function(item) {     return { name: item.fname, mp3: "http://example.com/" + item.song_id + ".mp3" };   });   var audioplaylist = new playlist("2", items); }); 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -