JQUERY POST AJAX JSON MOSTAR TABLA HTML DOM JS

https://www.studentstutorial.com/ajax/crud?expand_article=1

https://codeanddeploy.com/blog/php/ajax-search-data-in-php-mysql-using-jquery


function all() 

{

// Ajax config

$.ajax({

        type: "GET", //we are using GET method to get all record from the server

        url: 'all.php', // get the route value

        beforeSend: function () {//We add this before send to disable the button once we submit it so that we prevent the multiple click

            ajaxLoader("#employees-list", "show");

        },

        success: function (response) {//once the request successfully process to the server side it will return result here

            

            // Parse the json result

        response = JSON.parse(response);


            var html = "";

            // Check if there is available records

            if(response.length) {

            html += '<div class="list-group">';

            // Loop the parsed JSON

            $.each(response, function(key,value) {

            // Our employee list template

html += '<a href="#" class="list-group-item list-group-item-action">';

html += "<p>" + value.first_name +' '+ value.last_name + " <span class='list-email'>(" + value.email + ")</span>" + "</p>";

html += "<p class='list-address'>" + value.address + "</p>";

html += "<button class='btn btn-sm btn-primary mt-2' data-toggle='modal' data-target='#edit-employee-modal' data-id='"+value.id+"'>Edit</button>";

html += "<button class='btn btn-sm btn-danger mt-2 ml-2 btn-delete-employee' data-id='"+value.id+"' typle='button'>Delete</button>";

html += '</a>';

            });

            html += '</div>';

            } else {

            html += '<div class="alert alert-warning">';

  html += 'No records found!';

html += '</div>';

            }


            // Insert the HTML Template and display all employee records

$("#employees-list").html(html);

        },

        complete: function() {

        ajaxLoader("#employees-list", "hide");

        }

    });

}


///////////////////////////////////////////


html += '<div class="list-group">';

            // Loop the parsed JSON

            $.each(response, function(key,value) {

            // Our employee list template

html += '<a href="#" class="list-group-item list-group-item-action">';

html += "<p>" + value.first_name +' '+ value.last_name + " <span class='list-email'>(" + value.email + ")</span>" + "</p>";

html += "<p class='list-address'>" + value.address + "</p>";

html += "<button class='btn btn-sm btn-primary mt-2' data-toggle='modal' data-target='#edit-employee-modal' data-id='"+value.id+"'>Edit</button>";

html += "<button class='btn btn-sm btn-danger mt-2 ml-2 btn-delete-employee' data-id='"+value.id+"' typle='button'>Delete</button>";

html += '</a>';

            });

            html += '</div>';

            } else {

            html += '<div class="alert alert-warning">';

  html += 'No records found!';

html += '</div>';

            }


            // Insert the HTML Template and display all employee records

$("#employees-list").html(html);

Comentarios

Entradas populares de este blog

NUMEROS SERIE DE DISCO RIGIDO Y PENDRIVER USB CON PHP

INSERTAR Y UPDATE FECHA CON PHP MYSQL EN FORMULARIO METODO POST CON JQUERY ETIQUETA DATE

Copia de Seguridad de Archivo MS Access (.mdb) a Pendrive con VB6