Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在ajax响应后执行soundmanager2_Javascript_Php_Ajax_Soundmanager2 - Fatal编程技术网

Javascript 在ajax响应后执行soundmanager2

Javascript 在ajax响应后执行soundmanager2,javascript,php,ajax,soundmanager2,Javascript,Php,Ajax,Soundmanager2,我试图在ajax响应中执行一个脚本,但似乎找不到任何方法。我的脚本加载在html-head标记中,我还有一个带有id=“browsemusic”的div,在这里我的ajax响应指向 生成页面的我的php文件: include('dbcon.php'); if(isset($_REQUEST['all']) && $_REQUEST['all'] != ''){ //===============================Button "ALL"===========

我试图在ajax响应中执行一个脚本,但似乎找不到任何方法。我的脚本加载在html-head标记中,我还有一个带有id=“browsemusic”的div,在这里我的ajax响应指向

生成页面的我的php文件:

include('dbcon.php');
if(isset($_REQUEST['all']) && $_REQUEST['all'] != ''){
    //===============================Button "ALL"====================================
    unset($_REQUEST['kw']);
    unset($_REQUEST['genre']);
    $query = "select * from music";
    $result = mysqli_query($link, $query) or die (mysqli_error());
    echo '<ul id="sortable1" class="connected">';
    while($info = mysqli_fetch_array( $result )){
        echo '<li><div class="ui360"><button type="button" class="addtoplaylist" >Add</button><a href="' . $info['path'] . '"> '.$info['artist'].' - '.$info['title'].' ('.$info['album'].') '.'</a></div><hr /></li>';
    };
    echo '</ul>';
}elseif (isset($_REQUEST['kw']) && $_REQUEST['kw'] != ''){
    //============================= Search for music ================================
    $kws = $_REQUEST['kw'];
    $kws = mysqli_real_escape_string($link, $kws);

    $query = "select * from music where title like '%".$kws."%' or artist like '%".$kws."%'";
    $result = mysqli_query($link, $query) or die (mysqli_error($link));
    echo '<ul id="sortable1" class="connected">';
    while($info = mysqli_fetch_array( $result )){
        echo '<li><div class="ui360"><button type="button" class="addtoplaylist" >Add</button><a href="' . $info['path'] . '"> '.$info['artist'].' - '.$info['title'].' ('.$info['album'].') '.'</a></div><hr /></li>';
    };
    echo '</ul>';
}elseif(isset($_REQUEST['genre']) && $_REQUEST['genre'] != ''){
    //=====================================Browse By Genre ===========================================
    $genre = $_REQUEST['genre'];
    $genre = mysqli_real_escape_string($link, $genre);
    $gquery = "select music_id from musicgenre where genre_id = '$genre'";
    $results = mysqli_query($link, $gquery) or die (mysqli_error($link));
    $music=array();
    while($id_result = mysqli_fetch_array($results)){
        $music[] = $id_result['music_id'];
    };
    echo '<ul id="sortable1" class="connected">';
    foreach($music as $song){
        $query = "select * from music where music_id = '$song'";
        $result = mysqli_query($link, $query) or die (mysqli_error());;
        while($info = mysqli_fetch_array($result)){
        echo '<li><div class="ui360"><button type="button" class="addtoplaylist" >Add</button><a href="' . $info['path'] . '"> '.$info['artist'].' - '.$info['title'].' ('.$info['album'].') '.'</a></div><hr /></li>';
        };
    };
    echo '</ul>';
}else{
// ================================ Default =========================================

    $query = "select * from music";
    $result = mysqli_query($link, $query) or die (mysqli_error());
    echo '<ul id="sortable1" class="connected">';
    while($info = mysqli_fetch_array( $result )){
        echo '<li><div class="ui360"><button type="button" class="addtoplaylist" >Add</button><a href="' . $info['path'] . '"> '.$info['artist'].' - '.$info['title'].' ('.$info['album'].') '.'</a></div><hr /></li>';
    };
    echo '</ul>';
loadjscssfile()函数是我发现这种方法唯一有效的方法。问题是,如果我点击另一个调用同一个文件的类型(或另一个按钮,其中有一个具有相同功能的类似文件),它就会停止工作。所以它只在第一次起作用

解决了,我不得不重新启动ajax响应中的脚本。(soundmanager2有一个reboot()函数),因此ajax文件现在是:

$(document).ready(function(){
        $(".all").click(function()
    {
        var all = $(this).attr("id");
        if(all != '')
        {
            $.ajax
            ({
                type: "POST",
                url: "php/searchbrowselist.php",
                data: "all="+ all,
                success: function(option)
                {
                    soundManager.reboot();
                    $("#browsemusic").html(option);
                    $('#sortable1, #sortable2').sortable({
                        connectWith: ".connected"
                    }).disableSelection();
                }
            });
        }
        return false;
    });
});

将功能放在函数中,并在每次需要时调用该函数。哇!听起来它的名字“function”是有原因的。问题是它不仅仅是一个函数,它实际上是一个作为音频播放器工作的完整脚本。这里有许多功能(soundmanager2),请为您的手艺感到自豪。阅读脚本并找出它的作用。然后编写一个函数来实现这一点。像你正在尝试做的丑陋的黑客会崩溃;可能在你最不期望的时候,如果我将所有内容都包装到一个函数中,我会遇到一些构造函数错误。更简单的选择是使用具有实际接口的音频播放器。您可以尝试的另一种黑客方法是
$.globalEval
js文件的内容。这是一个相当令人发指的黑客行为。这对我也有帮助。谢谢:)
$(document).ready(function(){
        $(".all").click(function()
    {
        var all = $(this).attr("id");
        if(all != '')
        {
            $.ajax
            ({
                type: "POST",
                url: "php/searchbrowselist.php",
                data: "all="+ all,
                success: function(option)
                {
                    soundManager.reboot();
                    $("#browsemusic").html(option);
                    $('#sortable1, #sortable2').sortable({
                        connectWith: ".connected"
                    }).disableSelection();
                }
            });
        }
        return false;
    });
});