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.

    评论

报告相同问题?