dongluan7821 2015-10-14 09:40
浏览 24
已采纳

在`data`部分我的`$ .ajax()`调用有什么问题?

As first what I want, is when I scroll to the bottom of the page there will load 5 new posts from the database.

I'm doing a $.ajax() call where I give;

  • method: "POST"
  • url: "gastenboek_load_posts.php"
  • data: { 'rows': rows }

I did put an alert() on every single place to check where is goes wrong, and commented lines out of what I was thinking that was wrong.

And I came by the part of data: { 'rows': rows }

How can it be that this gives an error that says;

TypeError: 'click' called on an object that does not implement interface HTMLElement. http://code.jquery.com/jquery-latest.min.js Line 4

This is the whole jQuery code;

$(window).scroll(function() {
    if ($(window).scrollTop() == $(document).height() - $(window).height())
    {
        var rows = $("#feedback_field").find(".gb_list_item");

        $.ajax({
            method: "POST",
            url: "gastenboek_load_posts.php",
            data: { 'rows': rows}
        }).done(function(data){
            $("#feedback_field").append(data);
        });
    }
});

Maybe the PHP response code for if you need it what I think is not important for this problem;

<?
include_once 'core/init.php';
?>
<div id="feedback_field">
<ul>
    <?
    $a = 10;

    if (load_next_5_gb_posts($a) == false)
    {
        echo 'Alle gegevens zijn geladen!';
    }
    else
    {
        $posts = load_next_5_gb_posts($a);

        foreach ($posts as $data)
        {
            $a++;
        }
        ?><input type="hidden" id="new_posts" value="<?=$a?>"><?

        foreach ($posts as $posts)
        {
            ?>
            <li class="gb_list_item">
                <div id="poster">
                    <p><?=$posts['naam']?></p>
                    <p><?=$posts['email']?></p>
                    <p>
                        <?
                        $datum = $posts['datum'];
                        $week_days_en = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
                        $week_days_nl = array("Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag");
                        $months_en = array("January", "February", "Mart", "April", "May", "June", "July", "Augustus", "September", "October", "November", "December");
                        $months_nl = array("Januari", "Februari", "Maart", "April", "Meiy", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December");
                        $date = date_create($datum);
                        echo str_replace($week_days_en, $week_days_nl, str_replace($months_en, $months_nl, date_format($date,"l d F Y")));
                        ?>
                    </p>
                </div>
                <div id="msg">
                    <?=nl2br($posts['msg'])?>
                </div>
            </li>
        <?
        }
    }
    ?>
</ul>
</div>
  • 写回答

2条回答 默认 最新

  • dongli9894 2015-10-14 10:24
    关注

    I just found the solution!!!

    In the jQuery code this line needs the .length function;

    From

    var rows = $("#feedback_field").find(".gb_list_item");
    

    To

    var rows = $("#feedback_field").find(".gb_list_item").length;
    

    What is ectually very logical, cuz without that function I dont get the amount of the li's ;)

    Thx for you help guys!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码