weixin_33722405 2014-11-05 16:53 采纳率: 0%
浏览 11

AJAX未知问题

index.php (not exact layout just snippits)

        <!-- TRACK LIST -->
        <a name="trackList">
        <div id="trackList" class="container">
            <?php
                include("api/displayTracks.php");
            ?>
        </div>

        // AJAX
        function update(actionUrl, outUrl, div){        
            if (actionUrl != "") {
                $.ajax({
                    url: actionUrl,
                    cache: false,
                    success: function(html){        
                        $.ajax({
                            url: outUrl,
                            cache: false,
                            success: function(html){        
                                $(div).html(html);          
                            },
                        });         
                    },
                });
            } else {
                $.ajax({
                    url: outUrl,
                    cache: false,
                    success: function(html){        
                        $(div).html(html);          
                    },
                });     
            }
        }

        function updateTracks() {
            update("", "api/displayTracks.php", "#trackList");
        }

        setInterval(updateTracks, 5000);

I build the function update to try fix this issue, previously i had AJAX calls in many functions but the same problem persisted. The above code should update the #trackList with new content every 5 seconds... But my issue is it isn't doing anything, i haven't much experience with AJAX, this is as far as my knowledge span goes.

I did however place a alert('test') inside the update function and it successfully called every 5 seconds. So I've narrowed it down to the ajax.

displayTracks.php (the functions used in this are included at the top of index.php)

<?php
    // display tracks
    function displayLatestTracks($limit) {
        $sql = sql("SELECT * FROM tracks WHERE (rank > 0) AND (isSet = 0) ORDER BY date DESC LIMIT ".$limit);
        if (mysql_num_rows($sql) != 0) {
            while ($row = mysql_fetch_assoc($sql)) {
                if ($row['link'] != "") {
                    echo '<div style="background-color:rgb('.randColor().');" id="track-'.$row['id'].'" class="track">';
                    echo '<iframe width="100%" height="20" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url='.$row['link'].'&amp;color=b60000&amp;inverse=true&amp;auto_play=false&amp;liking=true&amp;show_user=true"></iframe>';
                    echo '</div>';
                }
            }
        }
    }

    // display albums
    function displayLatestAlbums($limit) {
        $sql = sql("SELECT * FROM tracks WHERE (rank > 0) AND (isSet = 1) ORDER BY date DESC LIMIT ".$limit);
        if (mysql_num_rows($sql) != 0) {
            while ($row = mysql_fetch_assoc($sql)) {
                if ($row['link'] != "") {
                    echo '<div style="background-color:rgb('.randColor().');" id="album-'.$row['id'].'" class="album">';
                    echo '<iframe width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url='.$row['link'].'&amp;color=c50000&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;liking=true&amp;show_reposts=false"></iframe>';
                    echo '</div>';
                }
            }
        }
    }
    echo '<p class="title">Track List</p>';
    displayLatestAlbums(3);
    displayLatestTracks(10);
?>

sql fucntion:

function sql($query) {
    $sql = mysql_query(strip_tags($query));
    if(!$sql) {
        echo "Error processing query".mysql_error();
    }
    return $sql;
}
  • 写回答

1条回答 默认 最新

  • weixin_33711641 2014-11-05 20:58
    关注

    There was in no way anything wrong with the AJAX. The way i arranged the include()'s in my php files deprived my AJAX code from gaining a direct mysql connection, resulting in the callbacks being blank and containing no data.

    评论

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?