I've been trying to load a PHP file dynamically using onload event in Jquery / Javascript. The following is the code I've written so far.
    <script>
    $(document).ready(function() {
        setInterval(function () {
                $('#alerts').load('alert-check.php', function () {
                    $('#notifID').click(function (e) {
                        e.preventDefault();
                        console.log("TRUE");
                    });
                });
            }, 1000);
    });
</script>
The php file loaded correctly every 1 second, but the problem is whenever I click the x button it is not working. inside the alert-check.php I have this code.
    <?php
include '../controller/action.php';
if(isset($_POST['dismiss'])){
    $id = $_POST['id'];
    $update = db_update('tbl_notif', $data = array("type"=>"Dismissed"), $where = array("id"=>$id));
}
$timenow = date('h:i:s');
$value = custom_query("SELECT * FROM tbl_notif WHERE type='Sticky' ORDER BY id DESC");
if($value->rowCount()>0)
{
    while($r=$value->fetch(PDO::FETCH_ASSOC)) {
        $r['content'];
        ?>
        <form id="alertForm" method="POST" action="">
            <div class="alert alert-info alert-dismissible" role="alert">
                <button type="submit" class="close" data-dismiss="alert" aria-label="Close" name="dismiss"><span aria-hidden="true">×</span></button>
                <input type="text" value="<?= $r['id']; ?>" id="notifID" name="id">
                <i class="fa fa-info-circle"></i> <p><?= $r['title']; ?></p>
                <p><?= $r['content']; ?></p>
            </div>
        </form>
        <?php
        if($r['intervals'] == '5m'){
            $t = date('h:i:s');
            $intervalResult = date('h:i:s', strtotime('+5 minutes', strtotime($t)));
            $update = db_update('tbl_notif', $data = array("notif_interval"=>$intervalResult, "type"=>"Sticky"), $where = array("id"=>$r['id']));
        }
    }
}
?>
I've been trying to solve this issue for a couple of weeks, any one please help me. Thank you.
 
     
     
    