errore http://datatables.net/tn/7

adatory

Nuovo Utente
3 Dic 2020
5
0
1
Buonasera, io sto creando questa datatable collegata ad un DB, quando entro sul sito mi sta questo errore e io non capisco quale problema può esserci nel codice per la creazione. Nel recipe.php ho lasciato la parte in ajax. Grazie per l'aiuto

recipe.php:

PHP:
<?php

<script>
$(document).ready(function(){

    var dataTable = $('#table_data').DataTable({
        "processing" : true,
        "serverSide" : true,
        "order" : [],
        "ajax" : {
            url:"../test/table_action.php",
            type:"POST",
            data:{action:'fetch'}
        },
        "columnDefs":[
            {
                "targets":[],
                "orderable":false,
            },
        ],
    });

    $('#add_table').click(function(){
        
        $('#table_form')[0].reset();

        $('#table_form').parsley().reset();

        $('#modal_title').text('Add Data');

        $('#action').val('Add');

        $('#submit_button').val('Add');

        $('#tableModal').modal('show');

        $('#form_message').html('');

    });

    $('#table_form').parsley();

    $('#table_form').on('submit', function(event){
        event.preventDefault();
        if($('#table_form').parsley().isValid())
        {       
            $.ajax({
                url:"../test/table_action.php",
                method:"POST",
                data:$(this).serialize(),
                dataType:'json',
                beforeSend:function()
                {
                    $('#submit_button').attr('disabled', 'disabled');
                    $('#submit_button').val('wait...');
                },
                success:function(data)
                {
                    $('#submit_button').attr('disabled', false);
                    if(data.error != '')
                    {
                        $('#form_message').html(data.error);
                        $('#submit_button').val('Add');
                    }
                    else
                    {
                        $('#tableModal').modal('hide');
                        $('#message').html(data.success);
                        dataTable.ajax.reload();

                        setTimeout(function(){

                            $('#message').html('');

                        }, 5000);
                    }
                }
            })
        }
    });

    $(document).on('click', '.edit_button', function(){

        var table_id = $(this).data('id');

        $('#table_form').parsley().reset();

        $('#form_message').html('');

        $.ajax({

              url:"../test/table_action.php",

              method:"POST",

              data:{id_ric:id_ric, action:'fetch_single'},

              dataType:'JSON',

              success:function(data)
              {

                $('#recipe_name').val(data.recipe_name);

                $('#modal_title').text('Edit Data');

                $('#action').val('Edit');

                $('#submit_button').val('Edit');

                $('#tableModal').modal('show');

                $('#hidden_id').val(table_id);

              }

        })

    });

    $(document).on('click', '.delete_button', function(){

        var id = $(this).data('id');

        if(confirm("Are you sure you want to remove it?"))
        {

              $.ajax({

                url:"../test/table_action.php",

                method:"POST",

                data:{id:id, action:'delete'},

                success:function(data)
                {

                      $('#message').html(data);

                      dataTable.ajax.reload();

                      setTimeout(function(){

                        $('#message').html('');

                      }, 5000);

                }

              })

        }

      });

});
</script>

recipe_action.php

PHP:
<?php

//table_action.php

include('../test/rms.php');

$object = new rms();

if(isset($_POST["action"]))
{
    if($_POST["action"] == 'fetch')
    {
        $order_column = array('recipe_name');

        $output = array();

        $main_query = "
        SELECT * FROM Ricette ";

        $search_query = '';

        if(isset($_POST["search"]["value"]))
        {
            $search_query .= 'WHERE recipe_name LIKE "%'.$_POST["search"]["value"].'%" ';
        
        }

        if(isset($_POST["order"]))
        {
            $order_query = 'ORDER BY '.$order_column[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' ';
        }
        else
        {
            $order_query = 'ORDER BY id_ric DESC ';
        }

        $limit_query = '';

        if($_POST["length"] != -1)
        {
            $limit_query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
        }

        $object->query = $main_query . $search_query . $order_query;

        $object->execute();

        $filtered_rows = $object->row_count();

        $object->query .= $limit_query;

        $result = $object->get_result();

        $object->query = $main_query;

        $object->execute();

        $total_rows = $object->row_count();

        $data = array();

        foreach($result as $row)
        {
            $sub_array = array();
            $sub_array[] = html_entity_decode($row["recipe_name"]);
            $sub_array[] = '
            <div align="center">
            <button type="button" name="edit_button" class="btn btn-warning btn-circle btn-sm edit_button" data-id="'.$row["table_id"].'"><i class="fas fa-edit"></i></button>
            &nbsp;
            <button type="button" name="delete_button" class="btn btn-danger btn-circle btn-sm delete_button" data-id="'.$row["table_id"].'"><i class="fas fa-times"></i></button>
            </div>
            ';
            $data[] = $sub_array;
        }

        $output = array(
            "draw"                =>     intval($_POST["draw"]),
            "recordsTotal"      =>  $total_rows,
            "recordsFiltered"     =>     $filtered_rows,
            "data"                =>     $data
        );
            
        echo json_encode($output);

    }

    if($_POST["action"] == 'Add')
    {
        $error = '';

        $success = '';

        $data = array(
            ':recipe_name'    =>    $_POST["recipe_name"]
        );

        $object->query = "
        SELECT * FROM Ricette
        WHERE recipe_name = :recipe_name
        ";

        $object->execute($data);

        if($object->row_count() > 0)
        {
            $error = '<div class="alert alert-danger">Table Already Exists</div>';
        }
        else
        {
            $data = array(
                ':recipe_name'            =>    $object->clean_input($_POST["recipe_name"]),
            );

            $object->query = "
            INSERT INTO Ricette
            (recipe_name)
            VALUES (:recipe_name)
            ";

            $object->execute($data);

            $success = '<div class="alert alert-success">Table Added</div>';
        }

        $output = array(
            'error'        =>    $error,
            'success'    =>    $success
        );

        echo json_encode($output);

    }

    if($_POST["action"] == 'fetch_single')
    {
        $object->query = "
        SELECT * FROM Ricette
        WHERE id_ric = '".$_POST["id_ric"]."'
        ";

        $result = $object->get_result();

        $data = array();

        foreach($result as $row)
        {
            $data['recipe_name'] = $row['recipe_name'];
            
        }

        echo json_encode($data);
    }

    if($_POST["action"] == 'Edit')
    {
        $error = '';

        $success = '';

        $data = array(
            ':recipe_name'    =>    $_POST["recipe_name"],
            ':id_ric'        =>    $_POST['hidden_id']
        );

        $object->query = "
        SELECT * FROM Ricette
        WHERE recipe_name = :recipe_name
        AND id_ric != :id_ric
        ";

        $object->execute($data);

        if($object->row_count() > 0)
        {
            $error = '<div class="alert alert-danger">Table Already Exists</div>';
        }
        else
        {

            $data = array(
                ':recipe_name'        =>    $object->clean_input($_POST["recipe_name"])
            );

            $object->query = "
            UPDATE Ricette
            SET recipe_name = :recipe_name
            WHERE id_ric = '".$_POST['hidden_id']."'
            ";

            $object->execute($data);

            $success = '<div class="alert alert-success">Table Updated</div>';
        }

        $output = array(
            'error'        =>    $error,
            'success'    =>    $success
        );

        echo json_encode($output);

    }

    if($_POST["action"] == 'delete')
    {
        $object->query = "
        DELETE FROM Ricette
        WHERE id_ric = '".$_POST["id"]."'
        ";

        $object->execute();

        echo '<div class="alert alert-success">Table Deleted</div>';
    }
}

?>
 

adatory

Nuovo Utente
3 Dic 2020
5
0
1
Scusa l'errore lo da quando apro il sito tramite un pop-up di chrome e l'errore è questo: DataTables warning: table id=table_data - Ajax error. For more information about this error, please see datatables.net/tn/7.

Non mi da nessuna riga e io non capisco dove sta il problema
 

macus_adi

Utente Attivo
5 Dic 2017
1.343
91
48
IT/SW
Non mi da nessuna riga e io non capisco dove sta il problema
If the server didn't reply to the Ajax request with a 2xx status code, we need to know what it did reply with, so we can take corrective action. So discovering what that reply was will be the starting point for resolving the issue full.
 

adatory

Nuovo Utente
3 Dic 2020
5
0
1
If the server didn't reply to the Ajax request with a 2xx status code, we need to know what it did reply with, so we can take corrective action. So discovering what that reply was will be the starting point for resolving the issue full.
I only see 404 as an error code
 
Discussioni simili
Autore Titolo Forum Risposte Data
C Meta tag http-equiv="X-UA-Compatible" errore validatore w3c HTML e CSS 3
T IIS attivo ma errore su http://localhost Classic ASP 1
catellostefano [URGENTISSIMO] si è verificato un errore in http server Apache 2
S HTTP 500 - Errore interno del server Classic ASP 6
K Inserimento query Errore 1366 PHP 4
F errore 1062 su campo nuovo MySQL 4
N Errore interno Access MS Access 2
R mi da errore dove inizia il while PHP 1
R Recupero di permalink di un sito che è stato eliminato per errore WordPress 5
R Yoast SEO errore semafori sempre rossi SEO e Posizionamento 0
S Visualizza l'errore di creazione in MSSQL Database 4
simgia Cordova errore quando cerco di emulare o creare la app Sviluppo app per Android 2
P Errore nell'indirizzo degli elementi HTML e CSS 2
Jensen Errore di sintassi con DELETE PHP 3
H Errore su array associativo PHP 1
FDF182 ERRORE 1292 PHP 4
P errore 404 con javascript Javascript 2
felino Windows 7: errore 80072EFE su Windows Update Windows e Software 1
M Errore visualizzazione meta tag title e description SEO e Posizionamento 1
A Errore durante il salvataggio Photoshop 0
M Errore configurazione motion detection nvr Hikvision DS-7616 IP Cam e Videosorveglianza 0
voldemort [c] Errore di segmentazione (core dump creato) C/C++ 1
T SSD - errore sistema Hardware 2
R Navigare sito con cURL, mi restituisce errore PHP 0
L File CSV con app inventor da errore Sviluppo app per Android 2
A Errore visualizzazione selezione testo Photoshop 0
I Postman 400 Errore di richiesta non valida Programmazione 0
S Errore PHP - Notice: Undefined index ... PHP 14
U Campo vuoto data errore Fatal error: PHP 2
R Errore UPDATE tabella mysql PHP 1
R W10 Segnalazione di errore su terminale USB Windows e Software 0
G non riesco a capire quale sia l'errore [SQL] MySQL 2
I Errore 80040220 nella newsletter con paginazione Classic ASP 0
E Errore di lettura php in html PHP 8
A php metodo post jquery non da mai errore jQuery 4
W Errore di run-time di Microsoft VBScript error '800a0035' Impossibile trovare il file Classic ASP 0
B Errore unexpected '$variabile' (T_VARIABLE) in your code on line PHP 2
M errore dopo passaggio Php 7.2 PHP 6
S -> Errore PHP 8
S Errore "ftp_put(): Can't open that file: Permission denied" PHP 1
P Errore telecamere hdcvi dahua IP Cam e Videosorveglianza 16
L form multipla php sql,errore in inserimento MySQL 0
M Errore JavaScript per php [objeto HTMLParagraphElement] PHP 0
F [PHP]Errore registrazione PHP 8
MarcoGrazia [PHP] Download di file con errore all'interno. PHP 1
V [ORACLE] Errore ora-06512 at sys.utl_file Oracle 0
A [WordPress] Errore Plugin WordPress 0
P [WordPress] Messaggio di errore in file style.css WordPress 0
G [Javascript] Errore inserimento dati Backend Node.js e workbench Javascript 1
M [PHP] WS-Security errore PHP 0

Discussioni simili