I have an ajax call on my index.php page that displays contents spit out by a controller. It sends information an a link click to itself and the content is displayed, the content is a list of the directories and files. It works great on the first click and shows the contents of the directory you clicked but when I click on the newly created link to show its content it runs forever and does not stop. Is there something wrong with my AJAX?
here is the AJAX it sends a couple variables each time:
<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>
and here is the index.php page I can not figure out why it runs nonstop. I figured it would just update the $_POST variables below and would run like before:
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);
}