你能把一个函数放在变量中吗?

时间:2013-04-05 18:16:20

标签: javascript jquery ajax json jplayer

我的问题出现了,因为我有以下代码,最后一部分不起作用,JPlayer的播放列表部分未声明

(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 is the callback function, which will run when your POST request returns

                function(postData) {
                    //Make sure to test validity of the postData here before issuing the GET 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);

我得到的问题是我得到播放列表“undefine”

会话变量包含以下内容

{"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"}

但是,如果我进行以下测试并且它完美运行

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

任何解释或帮助非常感谢

0 个答案:

没有答案