javascript - Can you put a function inside a variable? -
my question arises because have following code last part not work, part of playlist of jplayer not declared
(function($) { drupal.behaviors.myfunctiontheme = { attach: function(context, settings) { $('.add-music').click(function() { var songnew = json.stringify({ title: $(this).attr('data-title'), artist: $(this).attr('data-artist'), mp3: $(this).attr('href') }); var songie = { json: songnew }; $.ajax({ type: 'post', data: songie, datatype: 'json', async: true, cache: false }).done( //this callback function, run when post request returns function(postdata) { //make sure test validity of postdata here before issuing request var session; $.ajaxsetup({ cache: false }) $.get('/getsession.php', function(getdata) { session = json.parse(getdata); var myplaylist = new jplayerplaylist({ jplayer: "#jquery_jplayer_n", cssselectorancestor: "#jp_container_n" }, [session], { playlistoptions: { enableremovecontrols: true }, swfpath: "../js", supplied: "oga, mp3" }); }); }); }); } } })(jquery);
the problem get on playlist "undefine"
session variable contains following
{"title":"radio novela wagia. capitulo 1","artist":"","mp3":"http://red.comppa.com/sites/default/files/audios/radionovela%20wagia%20final.mp3"},{"title":"radio novela wagia. capitulo 1","artist":"","mp3":"http://red.comppa.com/sites/default/files/audios/radionovela%20wagia%20final.mp3"},{"title":"lenguas indígenas en los medios de comunicación","artist":"","mp3":"http://red.comppa.com/sites/default/files/audios/cun%cc%83alenguasindigenasenmediosdecomunicacion.mp3"}
but if following test , works perfectly
(function ($) { drupal.behaviors.myfunctiontheme = { attach: function(context, settings) { var session = [{"title":"radio novela wagia. capitulo 1","artist":"","mp3":"http://red.comppa.com/sites/default/files/audios/radionovela%20wagia%20final.mp3"},{"title":"radio novela wagia. capitulo 1","artist":"","mp3":"http://red.comppa.com/sites/default/files/audios/radionovela%20wagia%20final.mp3"},{"title":"lenguas indígenas en los medios de comunicación","artist":"","mp3":"http://red.comppa.com/sites/default/files/audios/cun%cc%83alenguasindigenasenmediosdecomunicacion.mp3"}]; var myplaylist = new jplayerplaylist({ jplayer: "#jquery_jplayer_n", cssselectorancestor: "#jp_container_n" }, session, { playlistoptions: { enableremovecontrols: true }, swfpath: "../js", supplied: "oga, mp3" }); }} })( jquery );
any explanation or thank much
Comments
Post a Comment