0

我的问题出现是因为我有以下代码,最后一部分不起作用,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);

我遇到的问题是我进入了播放列表“未定义”

会话变量包含以下内容

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

任何解释或帮助非常感谢

4

0 回答 0