0
It’s a notification system. The code below is working fine. When I click on the notification (
php file that generates notifications:
 <ul class="dropdown-menu">
      <li class="header">Você tem <?php echo $cont; ?> notificações</li>
      <li>
        <!-- inner menu: contains the actual data -->
        <ul class="menu">
<!-- Notificações  -->
         <?php
            foreach(variavel as variavel):
                (...)
                print '
                      <li>
                        <a onclick="sendData()" href="#">
                          <i class="'.$icone.'"></i> '.$nome.'
                          <input type="hidden" name="id" id="id" value="'.$id.'">
                        </a>
                      </li>';
            endforeach;
         ?>
        </ul>
      </li>
      <li class="footer"><a href="notif.php">Ver todas</a></li>
    </ul>
Function jquery/ajax:
<script>
function sendData()
{
    var idn = $('#id').val();
    $.ajax({
        type:"POST",
        url:"upd.php",
        data: { id: idn },
        cache: false,
    });
}
</script>
upd.php file:
(...)
$id = $_POST['id'];
$sql = "UPDATE notif SET status = 1 WHERE id = :id";
(...)
Perfect. It worked. However, can you help me with another problem that came up? <li> <a class="link-data" data-toggle="modal" href="#" data-target="#'. $not_id. '"> <i class="'. $not_icone. '"></i> '.$not_name. ' <input type="Hidden" name="idnot" id="'. $not_id. '" value="'. $not_id. '"> </a> </li>'; Bootstrap use. The modal is not opening when I put the input inside the 'a' or 'li' ... just outside the dropmenu
– AdrianoLeal
I did. Thanks to the code you posted, which solved the initial question I asked. I removed the input, put a class in the parent <li> and added the id variable to it and changed the line in the script: $(this). Parent('li'). attr('class'); PHP CODE: <li class="'. $id. '"> <a class="link-data" data-toggle="modal" href="#" data-target="#'. $id. '"> <i class="'. $icone. '"></i> '.$name. ' </a> </li> Grateful Fernando.
– AdrianoLeal
To open the modal try to use
$(seletor).click(function(){ $(seletor_do_modal).modal();});. How it stays inside the menu the event that is fired in the click goes to the function of the menu, I think that’s it.– fernandoandrade