AJAX呼叫永无止境

时间:2014-04-01 01:56:26

标签: php jquery ajax

我在index.php页面上有一个ajax调用,显示控制器吐出的内容。它向链接点击信息发送信息并显示内容,内容是目录和文件的列表。它在第一次单击时效果很好,并显示您单击的目录的内容,但是当我单击新创建的链接以显示其内容时,它将永远运行并且不会停止。我的AJAX有问题吗?

这是AJAX每次发送几个变量:

<script>
    var parent_dirs = "";
    var click_count = 0;

    jQuery('.container').on('click', '.show_content', function(e)
    {
        e.preventDefault();

        alert('called');
        var href = jQuery(this).attr('href');
        parent_dirs += jQuery(this).attr('id');
        click_count++;

        jQuery.ajax({
            url : "/",
            type: "POST",
            data : { link: href, parent: parent_dirs, click_count: click_count },
            success: function(data)
            {
                var result = jQuery(data).find('.content_result');    
                jQuery('.container').append(result);
            },
            error: function(thrownError)
            {
                console.log(thrownError);
            }
        });
    });
</script>

这里是index.php页面,我无法弄清楚为什么它会运行不间断。我认为它只会更新下面的$ _POST变量,并且会像以前一样运行:

include "../app/bootstrap.php";
include "../src/controllers/DisplayContentsController.php";

$link = (isset($_POST['link']) ? $_POST['link'] : null);
$parent = (isset($_POST['parent']) ? $_POST['parent'] : null);
$click_count = (isset($_POST['click_count']) ? $_POST['click_count'] : null);

if ($link != null)
{
    if($click_count == 1)
    {
        $full_path = $starting_file_path . '/' . $parent . $link;
    }
    else
    {
        $full_path = $starting_file_path . '/' . $link;
    }

    DisplayContentsController::show($twig, $starting_file_path . '/' . $link);
}
else
{
    DisplayContentsController::show($twig, $starting_file_path);
}

0 个答案:

没有答案
相关问题