Uncaught TypeError: Cannot read property '0' of undefined

Uncaught TypeError: Cannot read property '0' of undefined

simonksimonk Posts: 1Questions: 1Answers: 0

Bonjour,
J'ai un problème quand je passe mon écran en format tablette ou mobile les lien à l'intérieur de mon tableau ne fonctionne plus.

La console me retourne l'erreur suivante ->

Uncaught TypeError: Cannot read property '0' of undefined
at HTMLAnchorElement.<anonymous> (allAlerts.php:542)
at HTMLTableElement.dispatch (jquery.min.js.pagespeed.jm.r0B4QCxeCQ.js:1)
at HTMLTableElement.y.handle (jquery.min.js.pagespeed.jm.r0B4QCxeCQ.js:1)

Code HTML

<?php $sql = "SELECT * FROM alerts"; $result = $connect->query($sql); if($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $type = ($row['type'] == 1) ? 'Communiqué':'Alerte'; $active = ($row['active'] == 1) ? 'Oui':'Non'; echo ""; } } else { echo ""; } ?>
ID Titre Type Lien Actif Actions
ID Titre Type Lien Actif Actions
".$row['id']." ".$row['title']." ".$type." ".$row['link']." ".$active." Modifier Supprimer
Pas de données disponibles

Code JS ->

        $('#datatables').DataTable({
            "pagingType": "full_numbers",
            "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
            responsive: true,
            language: {
            search: "_INPUT_",
                searchPlaceholder: "Rechercher des enregistrements",
            }
        });


        var table = $('#datatables').DataTable();
        // Edit record
        table.on( 'click', '.edit', function () {
            $tr = $(this).closest('tr');

            var data = table.row($tr).data();
            var id = data[0];
            var link = './modifyAlert.php?id=' + id;
            window.location = link;

        } );



         // Delete a record
         table.on( 'click', '.remove', function (e) {
             $tr = $(this).closest('tr');

             var data = table.row($tr).data();
             var id = data[0];
             var url = './db_actions/deleteAlert.php';

             // Abort any pending request
             if (request) {
                 request.abort();
             }

             swal({
                 title: 'Êtes-vous sûr?',
                 text: 'Vous ne pourrez pas récupérer cette alerte!',
                 type: 'warning',
                 showCancelButton: true,
                 confirmButtonText: 'Oui, supprimer',
                 cancelButtonText: 'Non, annuler',
                 confirmButtonClass: "btn btn-success btn-fill",
                 cancelButtonClass: "btn btn-danger btn-fill",
                 buttonsStyling: false
             })
                 .then(function(isConfirm){
                     if (isConfirm.value) {

                         request = $.ajax({
                             type: "POST",
                             url: url,
                             data: { id: id }
                         });

                         // Callback handler that will be called on success
                         request.done(function (response, textStatus, jqXHR){

                             table.row($tr).remove().draw();
                             swal({
                                 title: 'Supprimé!',
                                 text: 'Votre alerte a été supprimée.',
                                 type: 'success',
                                 confirmButtonClass: "btn btn-success btn-fill",
                                 buttonsStyling: false
                             });

                         });

                         // Callback handler that will be called on failure
                         request.fail(function (jqXHR, textStatus, errorThrown){

                             swal({
                                 title: 'Error',
                                 text: 'L\'erreur suivante s\'est produite: ' + errorThrown,
                                 type: 'error',
                                 confirmButtonClass: "btn btn-info btn-fill",
                                 buttonsStyling: false
                             });

                         });

                     } else {
                         swal({
                             title: 'Annulé',
                             text: 'Votre alerte est en sécurité :)',
                             type: 'error',
                             confirmButtonClass: "btn btn-info btn-fill",
                             buttonsStyling: false
                         });
                     }
                 });
             e.preventDefault();
         } );

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.